Public Key SSH Authentication in PuTTY

Generating and using SSH authentication keys via PuTTY on Windows is a bit different from using a standard Bash shell in OS X or Linux. Here’s how it works:

First, connect to your SSH server; see the instructions for connecting via SSH on PuTTY if you haven’t done so yet. Once you are connected with your ssh user, make a new directory called .ssh:

  mkdir ~/.ssh

Make .ssh directory in PuTTY for public key authentication

Now open the PuTTYgen key generator from the PuTTY application folder and generate a public/private key pair. Save the keys somewhere (I used the Desktop in this case) but don’t close the window yet.

PuTTYgen privaate key for ssh

Copy and paste the public key from the key generator box into a plain text file labeled authorized_keys then save that file. Notepad will want to save the file with a .txt extension, which is fine for now.

PuTTY save public key in notepad

Now use PSFTP (also in the main PuTTY program file) to transfer authorized_keys.txt to the ~/.ssh directory you created on your VPS.

When PSFTP opens, connect to your VPS with your SSH user by entering open (replacing with your server IP address).

Once connected, change to the .ssh directory:

  cd ~/.ssh

Transfer authorized_keys.txt by typing put then dragging and dropping your new authorized_keys.txt file onto the PSFTP terminal, which will enter the filename and path for you. Hit enter.

Transfer public ssh key to server via PuTTY

Now rename authorized_keys.txt to authorized_keys:

mv authorized_keys.txt authorized_keys

rename authorized_keys in PSFTP

Now you can close PSFTP.

In PuTTY, connect using your keys by setting the private key you created earlier (in Connection > SSH > Auth):

PuTTY set private key

Now when you connect, you should only be asked for your username, not your password.

PuTTY successful public key authentication

For PuTTY to remember your SSH settings next time you want to connect, you will need to save them on the main basic settings page:

PuTTY save settings

If you got to this page from the SSH SOCKS server tutorial, be sure to return to that page and continue on with the rest of the security settings.