Skip to content
Kevin Thompson edited this page Oct 5, 2015 · 2 revisions

Introduction

In this section I'll shortly explain how to set up and use public key authentication for PuTTY. Of course, this also works for PuTTY Tunnel Manager. If you're interested in all the details, see the PuTTY documentation.

Public key authentication is an alternative means of identifying yourself to a login server, instead of typing a password. It is more secure and more flexible, but more difficult to set up.

The advantages are thus:

  • No need to remember or use usernames and passwords for all your SSH sessions.
  • More secure authentication

Getting started

  1. Download Pageant (pageant.exe) and PuTTYgen (puttygen.exe) from here and place it in some directory (can be the same directory as where PuTTY Tunnel Manager resides).
  2. I assume you have PuTTY, if not, get it as well

Creating a public and private key

  1. Start PuTTYgen (puttygen.exe).
  2. Click Generate and move the mouse over the blank area as indicated.
  3. Type in a password at Key passphrase (this is the only password you need to remember).
  4. Type it again at Confirm passphrase.
  5. Click Save public key and save it as "public_key.ppk" in your home directory.
  6. Click Save private key and save it as "private_key.ppk" in your home directory.
  7. Select the complete random text at the top (starting with "ssh-rsa") and copy it into a new text file.
  8. Save the text file as "public_key_for_authorized_keys.txt" (leave this file open for now).

Your public key can be given to anyone, or to every server. However, never, ever, give out your private key!

Adding your public key to a server

  1. Start PuTTY (putty.exe).

  2. Open a session to your desired server (that has tunnels, so you can use it with PuTTY Tunnel Manager) as usual and login.

  3. Type in the following commands:

     mkdir .ssh
     vi .ssh/authorized_keys
    

You just created a directory and opened up an editor.

  1. Copy the contents of the "public_key_for_authorized_keys.txt" file (that you left open earlier) and paste it into the editor.

  2. Save it by hitting the Esc-key and type ":wq" (without the quotes but with the colon) followed by Enter.

  3. Type in the following command:

     chmod -R 600 .ssh
     exit
    

This secured the just created file and closes the session.

Tip: You can do these steps for all servers you have in your session list.

Using public key authentication

  1. Start Pageant (pageant.exe).
  2. On the system tray, right click the Pageant icon, and click Add Key.
  3. Locate your private key (private_key.ppk) and open it.
  4. Type in your password for the key.

Tip: If you use PuTTY or PuTTY Tunnel Manager often, create a shortcut to Pageant followed by the location of your private key (ie. "C:\Program Files\PuTTY\pageant.exe" "%USERPROFILE%\private_key.ppk"). Place this shotcut in the Startup folder of your Start menu to have it start every time when Windows starts.

  1. Start PuTTY Tunnel Manager (ptman.exe).
  2. On the system tray, right click the icon and open the session that you copied your public key to.

You should no longer be asked for any password.