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:
- 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:
- When done the public key is shown and the Save buttons are enabled:
- Optionally you can enter a passphrase to protect your private key, please do so!
- Click on "Save private key":
- 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:
- With a text editor of your choice, open the authorized_keys file. If not existing, an empty one will be created:
- 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):
- 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":
- 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.
--
federico melaccio - 2014-07-11