Howto, windows

Howto: Passwordless SSH authentication with Putty

Credits: by MSH*, from Flickr CCHaving recently switched to Windows as my main desktop due to some work assignments, I’ve set up Putty to use encryption keys to handle my sessions – this way I don’t need to type in a password every time I need to open a new ssh session. Here is how to do it.

First of all, you need to get Putty from here. While Putty itself is only a tiny executable, I recommend you use the fullinstallable package, as we’ll use other apps from there such as PuttyGen and Pageant. Once installed, fire up PuttyGen and create a new pair of keys by clicking the “Generate” button. You can keep all the options at their default settings. It might be a good idea to set a passphrase for your key. Then, save both public and private key to a safe location. Name your public key <your_key_name>.pub and the private key <your_key_name>.ppk.

Now, upload your public key to a directory in your remote system. You need to import it and add it to the authorized_keys file with the command:

 ssh-keygen -i -f key.pub >> ~/.ssh/authorized_keys

Replace key.pub with the path to your key. Now log out and start Putty.

In Putty, configure the following items:

  • In Connection/Data, add your rmeote username
  • Connection/SSH/Auth, browse to your private key file (<your_key_name>.ppk)
  • Go back to Sessions, fill in the name or IP address of your remote machine, give your session a name and click on Save.

Now we need to set up Pageant – it is Pageant who will be doing the authentication for us. Open it up, right click on the icon in the system tray and select “Add key”. Select your private key. Now you have an item under “Saved sessions” in Pageant – clicking on your session will fire up Putty and Pageant handles authenticaton for you. Great eh? If your key has a passphrase, you will need to enter it only once, and after that Pageant remembers it for you.

Simple and a great time saver if you do this often ;)

Popularity: 46% [?]

some posts that may be related

  • Sam
    thanks buddy
  • Thanks, your post helped me implement passwordless authentication. I would like to add one thing which I have not seen in a lot of places:

    It has been documented that the .ssh directory in the user's home directory on the server must have a permission of 700.

    However, I realized that not only the .ssh directory, but also the user's home directory cannot give write access to 'group', and 'everyone'. The user's home directory on the server must have permission set to either 700 or 744 (704, 740, etc).
  • Thanks Parag, very helpful for any troubleshooting that might come up int he future...
  • "testsubjectalpha" is right abut it.
  • testsubjectalpha
    Hi!
    Thanks for this very detailed post!

    Just wanted to add one more thing: for these steps to work, the SSH server must support passwordless logins also!

    To enable this (and if you're doing this on your own machine/s), edit /etc/ssh/sshd_config as root. In it, uncomment the lines that say "PubkeyAuthentication yes". Also, puttygen.exe by default generates SSH2-RSA keys, so also uncomment the "RSAAuthentication yes" line

    Thanks again!
  • Nice! Just what I need!
  • Hugo Rodrigues
    great post!
  • Thanks Hugo, glad to help!
blog comments powered by Disqus