Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've somehow lost my id_rsa.pub file. I still have my id_rsa file. How do I recover the public key from the private key?

(This question came up after ssh-copy-id was reporting "ERROR: No identities found" while ssh-keygen reported "/root/.ssh/id_rsa already exists". ls ~/.ssh pointed out the problem was having id_rsa but not id_rsa.pub. I found the solution, but it was buried at the bottom of a long post on an Ubuntu support forum.)

share|improve this question
You can't just make another. OK I may be wrong – shakabra Sep 28 '12 at 11:11
up vote 13 down vote accepted

You can generate the public key using ssh-keygen -y. If your private key is in the default location, you can use the following to put the public key in the same place:

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.