Extract The SSH Public Key From A Private Key File

So, you’ve lost your public key but still have your private key. Or, maybe, you’ve downloaded the private key portion of the SSH key-pair that AWS (Amazon Web Services) generated and now you need the public portion (because AWS doesn’t give that to you for some reason).

It’s actually quite easy to get the public key out of the private key file. As long as you have access to ssh-keygen (which most modern linux distributions include.)

So, here’s how you extract your SSH Public Key:

  • Upload your private key file to a Linux server.
  • Change the permissions on the file to 600:
sudo chmod 600 yourfilename

You need to change the permissions otherwise ssh-keygen will refuse to handle the file.

  • Run the following command:
sudo ssh-keygen -y -f yourfilename

That should echo out the public key. Copy and paste it to a new file and you’re good to go!

Automatic Notification Of New Articles

Sign up to get automatic notifications of new articles.  This is a different list than our standard list - you only get new articles within 24 hours of publication.  No other emails will be sent unless you sign up for our general list in the footer of this site as well.

Posted in