Using Putty SSH Keys to Authenticate Automatically


There are a couple of ssh utilities that I find indispensable. Putty is THE ssh client for windows. It's free and it does everything I need it to. In fact over the last several years since I've been using it, I can only think of instances where it did more than I expected rather than coming up short feature-wise.

Putty can use a companion product Pageant to authenticate your ssh sessions automatically - which makes life easier when using utilities like WinCVS or WinSCP or similar software that might be dependent on ssh for functionality.

For some reason, over the years, I've had trouble setting up the auto-authentication. My own security paranoia has given me the mindset that I should delete my authorized keys regularly and only have auto-authentication set up for the occasions that I really need it. Since the times that I really need it are few and far between, I've frequently ended up having to re-learn how to get things set up. Since I found the answer in 20 seconds today, and the latest and greatest way to set it up is extraordinarily easy, i thought I'd share.

There is another companion utility that Mr. Simon Tatham has gracefully developed for us called PuttyGen. PuttyGen is a simple utility that creates public/private key pairs. It's all windows gui, and extraordinarily simple to use.

The problem with setting this all up that I've had in the past is that the keys generated by PuttyGen don't seem to work by simply copying and pasting them into my .ssh/authorized_keys file. I've had other issues in getting this set up in the past which I won't get into, but they surround other versioning and configuration settings that I have for my particular ssh implementations.

The solution is very easy, and I found it on this Open SSH Installation guide. I wouldn't be surprised if it has made it's way into Simon's documentation, but back when I actually did RTFM, it wasn't there.

Step 1) Generate your Private/Public key using puttygen. (just run puttygen, you don't need instructions)
Step 2) Save your private key somewhere that makes sense.
Step 3) Save your public key to a file also that makes sense. You probably will want to have it around for other purposes later anyways.
Step 4) Open up an ssh session with putty. Paste your public key into a new file. (right click is paste in putty.) Paste the whole thing from ---- BEGIN SSH2 PUBLIC KEY ---- to ---- END SSH2 PUBLIC KEY ----
Step 5) Run this command:

ssh-keygen -i -f putty-public-key > openssh-public-key

where putty-public-key is your existing public key file and openssh-public-key is the file you want your newly transformed key to sit.
Step 6) Either copy the openssh-public-key file to ~/.ssh/authorized_keys OR append the key in that file to your existing ~/.ssh/authorized_keys file.
Step 7) Start up Pageant. Right click the icon in the task bar and choose Add Key. Once the key is added, start up putty and you are all set.



Using Putty SSH Keys to Authenticate Automatically Interaction