SSH (Secure Shell) without password using Putty

SSH (Secure Shell) without password using Putty

SSH Protocol

SSH (Secure Shell) is network protocol which helps to securely access the computer, mostly Linux based computers.

SSH is one way to access the server. It combines security and accessibility for the data to be transmitted over the network. SSH protocol needs client-server architecture to connect to the remote server. An authentication method is required by the client computer in order to access the remote server through SSH. There are several ways to authenticate the user, such as:

  1. Password Authentication
  2. RSA Public Key Authentication

Password authentication is good, however, user needs to enter the password every time in order to access the server and it could lead to password breach.

PUTTY keygen

Authentication using Public key is secure and preferred over the network. Today, we will learn to setup PUTTY keygen on a Windows computer in order to remotely access Linux server over SSH.

Please follow these steps:

Download PUTTY

  1. Download the latest version of Putty.exe and Puttygen.exe on your Windows Computer: Download PUTTY
  2. Start puttygen.exe by double-clicking on the executable. The following window opens up:
  1. Leave the default ‘RSA’ selection and click on the ‘Generate’ button.
  2. You will need to move the mouse randomly over the progress bar to generate randomness in the generated key.
  1. Save Public and Private key on your computer is a safe location. You don’t need to enter a key phrase, it depends on your own discretion.

SSH connection to the remote server

  1. Now open PUTTY.exe and connect to the remote server using your username and password.
  2. Go to /etc/ssh/sshd_config file in order to verify if public-key authorization is enabled or not. Also, check the path of the public-key authorization enabled in the config file

Note
You might need root access to the server in order to open the sshd_config file. If you are not a root user, please contact the root user to confirm if public-key authentication is enabled or not.

  1. Once you open the file, scroll down to find ‘AuthorizedKeysFile‘ and check the path, I am showing you 2 different examples of sshd_config files:
  1. According to the first example, you can only create the ‘authorized_keys’ file. But, according to the second example, you can create either of the two files. Depending on your settings, you can continue further.
  2. Switch back to the original user.
  3. Go to the ‘home directory‘ by using the following command:
# cd ~
  1. Create a new directory by using the following command:
# mkdir .ssh
  1. Go in the newly created ‘.ssh’ directory and create a new file named as ‘authorized_keys’ or ‘authorized_keys2’ based on the information found in step 8, by using the following commands:
# cd .ssh
# nano authorized_keys

Note
You don’t need to be signed in as a root user, you can be signed in as a normal user as well.

  1. Copy the ‘Public Key’ from the PUTTYgen.exe application directly that was generated previously and paste it in the ‘authorized_keys’ file. In order to paste in PUTTY, you can use the ‘right-click’ of your mouse.
  2. Make sure that you have ‘ssh-rsa’ (including the spaces on both ends of the word) in the beginning and the whole key is written in a single line.
  1. Save the file and quit the text editor.
  2. Change the permission of the file ‘authorized_keys’ and the directory ‘.ssh’ as follows:
# chmod 600 authorized_keys
# chmod 700 .ssh

Setup Putty.exe

  1. Now, it is time to complete our setup!
  2. Exit the ssh connection and open the PUTTY.exe again.
  3. Go to Session and provide your remote server name or IP Address.
  4. Now from the left navigation, select Connection -> Data
  5. Enter the ‘Auto-login username‘.
  1. Next, scroll down and select Connection -> SSH -> Auth.
  2. Browse the Path of the saved private-key file and select your saved private-key.
  3. Save these settings for future reference.

Test your Setup

Now, PUTTY should connect to the remote SSH server and you won’t need any password prompt hereafter!

Caution
SSH is a powerful tool and relies on a password as security. We just bypassed that security for the sake of convenience. If a hacker gets holds of the private key we generated, it allows free access to your systems. So use this technique with care.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.