Use your PuTTY SSH Key on linux or Mac

26 11 2009

I look after an ever growing number of linux servers as part of my job, almost all of this I do remotely and with the help of our data centre.

All remote access is by secure keys NOT passwords. I use PuTTY SSH terminal on windows so I wanted to use the same key on my linux desktop with, as it happens, Gnome Terminal. I could have just generated a new key pair on linux but that seemed silly.

First export your PuTTY key using PuTTYGen Conversions option and Export as OpenSSH key. Save the file with a sensible name. This is your PRIVATE key, this is the part you DO NOT give out. If this ever does get out in the wild you need to remove the public key from all servers and build a new key pair. If you don’t have a password/pass-phrase on your key you should add one.

Now copy the exported private key to your linux (or Mac, its exactly the same process) home folder, or where ever.

OK, you now have your private key on your linux desktop (or Mac), you need to set the right file permissions on it, ‘chmod 700 private_key_filename’, if you don’t do this it wont work (and the number of times I’ve missed this part…)

Now you should be able to SSH into your server

ssh -p port -i private_key_filename username@hostname_or_ip_address

-p port — on my servers I run the SSH daemon on a different port to 22, if you use 22 you can omit that part

-i private_key_filename — is your key that you just copied

username — is the username on the server you are connecting to, if its the same as the username on your linux (or Mac) desktop then you can omit it

hostname_or_ip_address — obvious