SSH: Create Public Key from Private

Usually a public SSH key is generated at the same time as a private key.

Unlike a private SSH key, it is acceptable to lose a public key as it can be generated again from a private key at any time.

In this small note i am showing how to create a public SSH key from a private one using ssh-keygen command-line tool.

Cool Tip: Remove delay during SSH login! Read more →

Get Public SSH Key from Private

Use the following command to read a private SSH key from a file and print a public key:

$ ssh-keygen -y -f <keyfile>

Short explanation:

Option Description
-y Read a private OpenSSH format file and print an OpenSSH public key to stdout

As an example, let’s generate a public SSH key from a private key ~/.ssh/id_rsa and save it to the file ~/.ssh/id_rsa.pub:

$ ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Was it useful? Share this post with the world!

Leave a Reply