Enable Auto login in Putty using ssh keys

by admin on November 6, 2011

Putty is a tool for connecting to remote computers(Linux or Windows) through ssh or telnet protocols. When we open new connection to a remote computer using putty software, we need to provide username and password. This can be avoided by using ssh private and public keys. Below it’s explained how to generate these ssh keys and how to use them in putty. We also explain how to use these keys with Putty Connection Manager, the tabbed ssh client for Windows.

Generate Keys

(Below steps should be executed on the computer where ssh server is running.)
Firstly, set the right permissions on the .ssh directory. This is the place where we store the generated keys. Run the following commands.

chmod 700 .ssh
chmod 600 .ssh/authorized_keys

If authorized_keys file does not exist, create it with the below command.

touch .ssh/authorized_keys

Now run the command ssh-keygen. This will generate public and private keys. You will be prompted to enter some passphrase, you can leave it empty if you want.

[user@linux-pc ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
78:94:6d:83:66:78:81:89:89:59:fb:1a:aa:a7:c2:e8 user@linux-pc
[user@linux-pc ~]$

Move the public key to .ssh/authorized_keys file.

cat .ssh/id_rsa.pub >> .ssh/authorized_keys

Make sure to append the key (‘>>’), otherwise existing keys in the authorized_keys will be deleted.

Configure Putty Client

  1. Copy the private key generated on the server to the client computer from where you will be connecting to the server.
  2. The private key we have is open-ssh key and putty does not understand this. We need to convert this private key to something that putty understands.  For this we will use the tool PuttyGen. Click on the link to download this file.
  3. Launch PuttyGen tool.  Generate ssh private key using puttygen
  4. Click on the Load button, and select the private key file we copied from the server.
  5. You will also need to enter the pass phrase you used for generating the keys in ssh-key command.
  6. Save the generated private key using the ‘Save private key‘ button.

    save the generated private key in puttygen tool

  7. Now launch Putty tool.
  8. Go to the node Connection -> Data. In the text box ‘Auto-login user name‘ enter your login name on the server
  9. Go to the node Connection -> SSH -> Auth
  10. Click on browse button and add the path for the private key file which we saved in step 6.
  11. Now go to the ‘Session‘ in the settings. Enter a new name under ‘Saved sessions‘ and save it. Enable auto-login in putty connection manager
  12. Now onwards whenever you want to connect to this server, you can select this session and lick on ‘open‘ button. If you have chosen empty passphrase in the key generation, ssh connection will be established automatically.  Otherwise, you will be asked to enter the passphrase and then connection will be established.

Auto login with Putty connection manager:

You can use the session created above to do auto login from Putty connection manager. Do the below steps for this.

  • Open connection configuration settings for the server for which we are enabling auto login.
  • click on ‘PuTTy Session
  • Select the new session we have just created in Putty.Enable auto login in putty connection manager for ssh connections
  • Click on Apply and close the window
  • Now if you open new connection tab in PuttyCM, you will be connected to the server without being prompted for password.

{ 2 comments… read them below or add one }

alphonso September 8, 2012 at 4:17 am

wow – clear – precise – that saves me a lot of time – work of pros. Thanks.

Reply

gary September 25, 2012 at 8:09 pm

I’ve searched everywhere – seems like – and can’t find an instance of this. From my laptop running Win 7, using PuTTY, I can tunnel to my router – Linksys WRT54GL with dd-wrt mini firmware setup as the SSH server – as long as I’m on my home network, either wired or wirelessly, but can’t when I’m somewhere else on a public network. The keys work fine. When I open the session on a public network, I just get the PuTTY window with a blank screen and blinking cursor. On the home network it logs me in and asks for the passphrase for the key, and then takes me to the DD-WRT logo and the linux command prompt.

Anyone know what gives?

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: