Friday, January 09, 2009

Configuring PuTTY to use PKI (passwordless) authentication

Since this is about using PuTTY I would recommend you download it if you haven't already. Also you will need to get PuTTYgen, it might be worth it to grab pscp as well. I like to keep putty.exe and puttygen.exe in my Windows directory, so I don't have to update my path, thus allowing me to run putty right from the command prompt.

Now run PuTTYGen and create a new pair of keys by clicking the “Generate” button. You will have to move your mouse around in the box to generate randomness, so keep doing that until the progress bar fills up. You can keep all the options at their default settings. 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 on your remote system. I used pscp to do this quickly to all of my servers (pscp [your_key_name.pub] user@remotesystem:)
Now you have to import your public key into the authorized_keys file (and authorized_keys2)

ssh-keygen -i -f [your_key_name.pub] >> .ssh/authorized_keys && ssh-keygen -i -f [your_key_name.pub] >> .ssh/authorized_keys2
Replace [your_key_name.pub] with the path to your key. Now log out and start PuTTY.
In Putty, you have to configure the following items:
In Connection/Data, add your remote user name
In Connection/SSH/Auth, browse to your private key file (.ppk)
In Sessions, fill in the FQDN or IP address of your remote machine, give your session a name [session_name] and click on Save.

Now you can use putty to SSH into your remote boxes with out a password. If you are a fan of having one or two click shortcuts create a shortcut to %windir%\putty.exe -load [session_name]. If you gave your [session_name] a name with spaces use double quotes to encase it like putty.exe -load "session name".

1 comment:

Jonathan said...

Thank you so much for this tutorial !!