Windows SSH Keys

Logging Into a Unix System from Windows Without a Password

Wouldn’t it be great if you could open a putty session without entering your username and password everytime.  You can do this by saving your password in putty but a better way is to setup ssh keys. Once you have the key, this can be setup for a variety of programs.

Setting up key based logon from Windows is relatively simple. First, you’ll need Puttygen which will be used to generate the key pair on your Windows system. Start Puttygen, leave the default of SSH-2 and click Generate. It will ask you to move the mouse around to create randomness used to generate the key.

So now we have our public and private keys generated.  The private key will stay on our windows box and the public key will go to the target Unix server. At this point it will be good to save both the public and private key. The private key is saved with a .ppk extension and will be used by other applications.

Now copy the public key (the part highlighted in the above example) and paste it into your authorized_keys2 file on your Unix server. It should be under the .ssh directory of your home directory.   Be sure it goes in as one line so there are no line breaks or the file will be corrupted. Now the public key is in place on the Unix server so we need to specify the private key on our Windows side to get this to work and there are a couple of ways to do that. For putty we can specify our key file and user id. In your putty configuration on the left of the screen go to Connection | SSH | Auth and Browse to your private key file.

That takes care of the key but it doesn’t what username to logon with.If you try to login now you’ll get a login prompt for the username but not for the password.

 

login as: mijordan

Authenticating with public key "rsa-key-20070824" from agent

Last login: Tue Aug 28 11:41:21 2007 from 10.131.246.17

Use of the Network is restricted to authorized users.  User activity

is monitored and recorded by system personnel.  Anyone using the

Network expressly conssents to such monitoring and recording.

So we’re halfway to automated logon. Go back into your putty configuration and go to Connection | Data. Enter your username under the “Auto-login username.” Now save those setting to your desired session and you’re done. When you open putty now, just select the saved session and it should open up and automatically log you in. There is another way to accomplish this by using a program called pageant. When you run pageant you select a private key file to load and then you minimize it. You will see the icon on your Windows toolbar. With pageant running you could skip the step of loading the private key in putty and this is useful for key-based logon in other apps like pscp. But for a permanent solution, just specify your keyfile within putty itself. Also note that if you are using WinSCP you can also load the private key there to get automated logon. In the session information just specify the location of the private key and your username you’re done.