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.
(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.
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.
[[email protected] ~]$ 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 [email protected] [[email protected] ~]$
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
- Copy the private key generated on the server to the client computer from where you will be connecting to the server.
- 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.
- Launch PuttyGen tool.
- Click on the Load button, and select the private key file we copied from the server.
- You will also need to enter the pass phrase you used for generating the keys in ssh-key command.
- Save the generated private key using the ‘Save private key‘ button.
- Now launch Putty tool.
- Go to the node Connection -> Data. In the text box ‘Auto-login user name‘ enter your login name on the server
- Go to the node Connection -> SSH -> Auth
- Click on browse button and add the path for the private key file which we saved in step 6.
- Now go to the ‘Session‘ in the settings. Enter a new name under ‘Saved sessions‘ and save it.
- 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.
- 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.