How to Setup Passwordless SSH Login?

SSH (Secure Shell) is the network protocol that is utilized for logging servers and executing commands remotely. The password key is required for authentication to log in to the server. While configuring a remote server, administrators require remote access repeatedly.

Considering the issue, this guide will set up the passwordless SSH login (public key authentication). The supported content of this guide is as follows:

Let’s start with the first method.

Method 1: Upload Public Key to Remote Server

The passwordless authentication does not need to enter a password for new sessions. To setup passwordless SSH login, the step-by-step procedure is mentioned below:

Step 1: Generate Key

To generate the SSH public/private key pair, the “ssh-keygen” is utilized with the “t” option that specifies the type of key generation protocol “rsa” as below:

$ ssh-keygen -t rsa

The output shows that the public key has been successfully generated.

Note: Users can access the “.ssh/id_rsa.pub” file to verify the public key. 

Step 2: Upload Key to Server

The second step is to upload the (public) key to the remote server. For instance, copy the public key and upload to the server by specifying the “remote-user” and “server-ip” below:

$ ssh-copy-id [email protected]

The output verifies that the key has been added to the remote server after authentication.

Verify Passwordless SSH Login

To confirm the passwordless authentication, the remote server’s username and ip address is required as below:

The output confirms that remote user “roger” is accessed without any password.

Method 2: Disable Password Authentication

Another method is considered to set up the passwordless SSH login by accessing the “sshd_config” file. The step-by-step procedure is provided below:

Step 1: Access the sshd_config File

The “sshd_config” file is accessed using the “nano” editor using the command shown below:

$ sudo nano /etc/ssh/sshd_config

It navigates to the “sshd_config” file through the nano editor. After accessing the file, change the “PasswordAuthentication”  value from “yes” to “no” as below:  

Step 2: Restart SSH Service

After changing the value, restart the ssh services by executing the below script:

$ sudo systemctl restart ssh

Verify Passwordless SSH Login

To confirm the passwordless authentication over SSH, the username and ip address of the remote server is checked as below:

The output authenticates that remote user “roger” is accessed without any password.

These are all the methods to set up an SSH login without a password.

Conclusion

In Linux, the passwordless SSH login is set up by uploading a public key to a remote server and disabling the password authentication after accessing the “sshd_config” file. This article has explained all possible methods to set up passwordless SSH login authentication.