Migrate ssh keys for new computer


This post is more than 5 years old. While math doesn't age, code and operating systems do. Please use the code/ideas with caution and expect some issues due to the age of the content. I am keeping these posts up for archival purposes because I still find them useful for reference, even when they are out of date!

I need to use a set of ssh keys on a new machine. In general, it is probably best to generate new keys instead of copying old keys, but this is a temporary solution for now.

So, given that disclaimer, I copied the ~/.ssh folder from the old machine into a temp folder on the new machine. This avoids copying over anything in the new machine's ~/.ssh folder. Copy all keyname, keyname.pub files to ~/.ssh. Also, copy the ~/.ssh/config (if you have one). Finally, the new computer needs to add the keys. Do this with command for each key:

$ ssh-add keyname

You will be prompted for the password for the key (if any). Now, try the keys out. You should be able to ssh to all of the machines covered by the added key(s).

Potential Problems

There can be a variety problems with the above process. The above worked for me without modification. However, I think that file ownership and permissions can be problematic. One solution for ssh permissions problems is available just in case.