One at a time

Howto: Passwordless SSH authentication with Putty

Multiple Padlock Farm Gate Mechanism - multi-lock-gate-at-islay-creek-road-montana-de-orophoto © 2008 Mike Baird | more info (via: Wylio)
Having 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: 59% [?]

  • Hugo Rodrigues

    great post!

  • http://dailyiteration.com garrido

    Thanks Hugo, glad to help!

  • http://thinkweird.info thinkweird

    Nice! Just what I need!

  • Pingback: PuTTY配合SSH服务器飞跃防火墙 | 西瓜博客

  • Pingback: stev.ie/ » Blog Archive

  • 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!

  • http://www.bidbuy.ro/ licitatii

    “testsubjectalpha” is right abut it.

  • http://www.adaptivelearningonline.net Parag Shah

    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).

  • http://dailyiteration.com garrido

    Thanks Parag, very helpful for any troubleshooting that might come up int he future…

  • http://dailyiteration.com garrido

    Thanks Parag, very helpful for any troubleshooting that might come up int he future…

  • Pingback: PuTTY配合SSH服务器飞跃防火墙 « 海纳百川

  • Pingback: idliqgxy

  • Pingback: qpdisdin

  • Pingback: PuTTY配合SSH服务器飞跃防火墙 | 海纳百川 Linux

  • Sam

    thanks buddy

  • Locke Door

    He's not your buddy, pal.

  • Vladko_t

    easy and VERY helpful!

  • http://dailyiteration.com garrido

    Thanks Vladko_t, glad you enjoyed it.

  • http://dailyiteration.com garrido

    Glad you liked it Sam ;)

  • http://twitter.com/lukystreik Gustav Ludwig

    Many many thanks! There are several manuals in internet, but no one says, that you have to set the “auto-login username” in putty section connection/data. So i wasted hours in installing pageant and passwordless putty login. Login via commandline is also possible with: putty.exe user@servernameorip:id_rsa

  • http://twitter.com/lukystreik Gustav Ludwig

    sorry i posted twice :

  • http://dailyiteration.com garrido

    Thanks Gustav, glad the post was useful to you. And thaks for the tip about the command line login, I wasn’t aware you could do that.

  • http://openid.littlebearz.com/openid/./conf.php littlebear91

    Wow, where have I been lol, I’ve been using mstsc.exe since i had to type so much t.t

  • Anonymous

    You might also have to chmod 600 authorized_keys

    P.S, I didn’t have to do anything with pageant to be able to get authorized