Tags:
create new tag
view all tags

How to use SSH keys with PuTTY

This article describes how to use PuTTY for passwordless SSH access via public/private key pairs.

  • Open the PuTTYgen utility which comes along the PuTTY suite of programs:
PuTTYgen1.png

  • Click on Generate to start generating a public/private key pair
  • You are asked to generate some randomness by moving the mouse on the area below the progress bar:
PuTTYgen2.png

  • When done the public key is shown and the Save buttons are enabled:
PuTTYgen3.png

  • Optionally you can enter a passphrase to protect your private key, please do so!
  • Click on "Save private key":
PuTTYgen5.png

  • Enter a name and select a destination folder, then click "Save". IMPORTANT: This file MUST reside on your computer and it cannot leave it or be sent over any network.
  • Do likewise for the public key (click on "Save public key").
  • Now go back to the PuTTYgen main screen and select the public key with the mouse, right click on the selection and copy it.
  • Open a new PuTTY session to the Linux machine you want to connect via those SSH keys.
  • At prompt, cd to .ssh/ folder:
authkey1.png

  • With a text editor of your choice, open the authorized_keys file. If not existing, an empty one will be created:
authkey2.png

  • Go to the end of file and paste the public key as a new line (middle or right mouse buttons click when in text editing mode):
authkey3.png

  • Save, exit and close the PuTTY session. Now you need to tell PuTTY to use the new key pair.
  • Go back to the PuTTY main window, load your saved session settings from the Session tab.
  • Go to Connection -> SSH -> Auth and click on "Browse":
PuTTYgen6.png

  • Select the private key file you saved previously and click "OK".
  • Go back to the Session screen, and save the new session settings for future use.
  • You are done! Try to connect: you should go straight to the shell prompt with no password request.

Possible issues

If you are still prompted for a password, try the following:

  • Make sure you did not miss any character in the copy/paste of the public key. If not sure, copy it again from the saved public key file and re-do the paste.
  • Check the authorized_keys permissions if creating a new file. They must be 644 (see the chmod man page).
  • Make sure your private key is loaded into the PuTTY session.

Automating Things with pagent

If you have protected your key with a passphrase (which you mush do) you will not be prompted for you Linux password by the remote machine and you will not be sending you password across the network (even encrypted) but you will still be prompted for you key passphrase each time, which is not much better for you.

To avoid that we need to use an agent to remember the private key for you, for putty the agent is called pagent, it should be in the same folder as PuTTYgen. When you start it up it appears not to have worked because no window opens up. What it has done in put a new icon in your system tray right click on that and select "Add Key", open the private key file you save from PuTTYgen and enter you passphrase when prompted (you do have a passphrase don't you).

Once you key is loaded up, start a new PuTTY session by right clicking on the pagent icon in the system tray and selecting "New Session". Then Load up the previous session that you saved and remove the "Private key file for authentication" under the Connection -> SSH -> Auth section, and click "Open" . You should get logged in without being prompted for an SSH key passphrase or for your Linux Password.

Open the putty config again, remove the "Private key file for authentication" again and this time save the config under the "Session" tab.

You should now be able to open as many sessions as you like by right clicking on the pagent icon and selecting your saved config under "Saved Sessions"

-- chris brew - 2018-11-09

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng PuTTYgen1.png r1 manage 29.9 K 2014-07-11 - 11:41 FedericoMelaccio  
PNGpng PuTTYgen2.png r1 manage 33.5 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng PuTTYgen3.png r1 manage 40.1 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng PuTTYgen4.png r1 manage 41.9 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng PuTTYgen5.png r1 manage 100.8 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng PuTTYgen6.png r1 manage 35.6 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng authkey1.png r1 manage 45.9 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng authkey2.png r1 manage 49.6 K 2014-07-11 - 11:42 FedericoMelaccio  
PNGpng authkey3.png r1 manage 40.3 K 2014-07-11 - 11:42 FedericoMelaccio  
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2018-11-09 - ChrisBrew
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback