Skip to content

Instantly share code, notes, and snippets.

@bench
Last active January 16, 2018 15:10
Show Gist options
  • Save bench/c371d4c0fdca36eed5ef4af251ae72b0 to your computer and use it in GitHub Desktop.
Save bench/c371d4c0fdca36eed5ef4af251ae72b0 to your computer and use it in GitHub Desktop.
generate private and public rsa keys

First option

$ 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==

Second option

ssh-keygen -b 4096 -C "username@host" -N "" -f my.key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment