Move SSH Keys From One Computer to Another

Jul 13, 2012 - 4 Comments

Move SSH Keys from one computer to another

For those that rely on passwordless logins via ssh, rather than generating a new SSH key for a new client machine, you can easily move SSH keys from one computer to another. This is a quick and easy solution for a temporary machine or username or for use on an auxiliary workstation. You could also use this to copy SSH keys between user accounts on the same machine.

Moving SSH Keys Between Computers

If you’re already connected to a networked Mac, using the Finder is an easy way to copy the SSH keys. First you’ll want to show hidden files in OS X either through defaults write or a tool like DesktopUtility, then just open up the .ssh directory on both machines and do a drag and drop:

Migrate SSH Keys through Finder

On the other hand, if you’re already in Terminal to enable hidden files, you may as well just use the command line to move them over.

Copying SSH Keys from the Command Line
Using the terminal is faster for many of us, you’ll obviously have to be connected to the other computer through a network for this to work.

cp .ssh/id_rsa* /Network/path/to/username/.ssh/

Simple enough, and will work for any version of OS X and most variations of unix or linux.

If you wanted to, you could also zip the key files and then transfer them through AirDrop, but that’s probably more work than necessary.

Because SSH keys allow for passwordless logins, you’ll want to securely delete or better yet securely format the hard drive before it goes to a new owner. This is especially true with temporary computers or loaner machines.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. Jacqueline says:

    Thank you for this article.. I’ve been looking _everywhere_ on a solution on how to copy my machines to my second mac and couldn’t find anyone it seemed who had a similar issue. That or its obvious I have barely any idea what I’m doing. Thanks again!

  2. Wojtek says:

    Um. I’m pretty sure that if someone knows about the ssh keys, they are perfectly fine copying them using terminal or the like, and *not* using the Finder for it… Also, allowing users who don’t know what ssh keys are to play with them is just asking for trouble…

  3. Can I move the /.ssh folder to my Dropbox and create a symbolic link to it? So I will never forget to backup my SSH keys when I buy a new computer for example or if something goes wrong with it???

  4. jch says:

    There’s no need to copy your ssh key around. Just put

    ForwardAgent: yes

    in a file called ~/.ssh/agent. It will be forwarded automatically and securely provided it has been loaded into the local agent with “ssh-add”. You can see what key (or keys) are currently loaded into the agent with “ssh-add -L”. This also means that there is no excuse for not having a really secure password for your private key.

    Don’t use private keys without a secure, a really secure, password. It’s just too dangerous.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site