$ openssl genrsa -out mykey.pem 1024 # build rsa private key
Generating RSA private key, 1024 bit long modulus
............................................................++++++
....++++++
$ openssl rsa -in mykey.pem -pubout > mykey.pub # build --BEGIN PUBLIC KEY-- format public key
writing RSA key
$ cat mykey.pub
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/jHd5Jeml/271b3fxmNq6h+hq
PDr6eyQm2xS4L/rAjSJV+V7uM4NuK0gk7w/zxEo7oa6m1tgcIH4KsaSTISnskrUI
Oz0fWv/IJJockKv89qDQsVqNKng4EtdZJNcZt56f1CHrUaxrgdJWO835b+JOq45y
hNtzsEbOPo5ZRteK6QIDAQAB
-----END PUBLIC KEY-----
$ ssh-keygen -f mykey.pub -i -mPKCS8 # build rsa format private key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABARZFgQC/jHd5Jeml/271b3fxmNz0h+hq6UebPHQm2xS4L/rAjSJV+V7uM4NuK0gk7w/zxEo7oa6m1tgcIH4KsaSTISnskrUIOz0fWv/IJJockKv89qDQsVqNKng4EtdZJNcZt56f1CHrUaxrgdJWO835b+JOq45yhNtzsEbOPo5ZRteK6Q==
ssh-keygen -b 4096 -C "username@host" -N "" -f my.key