How to Setup Passwordless SSH Login in Linux

How to Setup Passwordless SSH Login in Linux
How to Setup Passwordless SSH Login in Linux

Setup Passwordless SSH Login in Linux

SSH stands for Secure SHELL protocol which is an opensource and mostly used network protocol. SSH secures connections between client and server systems. By using scp command with SSH you can transfer files between two systems. SSH supports different authentication protocols in which password based and public key based authentications mostly used today. In this tutorial, you are going to learn how to setup Passwordless SSH Login in Linux.

Setting up Passwordless SSH Login

Here first we will generate a public authentication key by checking if its already exists or not then we will setup passwordless ssh login. Follow below instructions to setup passwordless ssh login.

Step 1: Check SSH key paire

Here in this step, we will first check if SSH key pair already exists. If it doesn’t exist then we create a new one. To check it please run following ls command in the terminal:

ls -al ~/.ssh/id_*.pub

If the key exists then you can go with them and skip to step 3. Otherwise, you can backup existing keys and generate new keys by using the next step.

If you don’t have existing ssh keys then you can generate new ones using next step.

Step 2: Generate New SSH key pair

To generate new ssh key pair you can run following command by replacing [email protected] with your email address:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Now you will be asked for file to save new keys. Its recommended to press ENTER and go with default file:

Enter file in which to save the key (/home/linux4one/.ssh/id_rsa):

Next, you will be asked to enter a passphrase. If you want to set up a passphrase then you can enter a passphrase and confirm it. Generally to automate the processes SSH is used without a passphrase. If you don’t want to set passphrase then just press

ENTER</pre:
Enter passphrase (empty for no passphrase):

Now to confirm the keys are generated run following command:

ls ~/.ssh/id_*

You should get output like following:

/home/linux4one/.ssh/id_rsa /home/linux4one/.ssh/id_rsa.pub

Step 3: Copy Public Key to Remote System

Now you should copy the public key from your system to a remote system by using ssh-copy-id command. To do so you can run the following command by replacing REMOTE_USER with the remote host username and SERVER_IP_ADDRESS with your remote system IP Address. If you dont know your serve IP address you can get one by using ping command:

ssh-copy-id [email protected]_IP_ADDRESS

Next, you will be asked to enter remote hosts password:

[email protected]_IP_ADDRESS's password:

Now public keys will be coppied to the authorised keys file by closing connection.

Step 4: Login to the remote system

Now you can login to remote system without password (passwordless). To login run following command in the terminal:

ssh [email protected]_IP_ADDRESS

Conclusion

Here you have successfully learned How to Setup Passwordless SSH Login in Linux. If you have any queries regarding this then please don’t forget to comment below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here