Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

This question already has an answer here:

I need help on exporting both private keys and public located in ssh into one file. id_rsa and

share|improve this question

marked as duplicate by Alvar, mikewhatever, BuZZ-dEE, guntbert, Seth Feb 2 '14 at 21:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

One file containing both keys, Why? – enzotib Jan 18 '12 at 10:02
Just for back up. Because we are transferring our office to new location, i don't know to by boss. – noxmart Jan 19 '12 at 1:49

You can restore a public key from the private key file with ssh-keygen.

ssh-keygen -y -f /path/to/private/key

Saving both keys in the same file is not neccessary and not supported. You could however simply use cat to combine them for archiving purposes or whatever you're planning.

cat id_rsa > combined

However this keyfile will not be readable by ssh in the way you may think it is. To restore these key files, you will have to split them up and save them in seperate files again.

share|improve this answer
Meaning, I just need to export the private key and from there, I can restore my public key. right? – noxmart Jan 19 '12 at 1:29
Yes. If your private key is protected with a password, you will need that password to restore the pubkey. You can easily test this by just using ssh-keygen -y -f /path/to/private/key and compare the output to the contents of your pubkey. – bkzland Jan 19 '12 at 9:14
@bkzland There is no point in combining the public key with the private key in a single file if all the data of the public key is already available in the private key and can be restored. – dolmen Sep 2 '13 at 12:06

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