We might be required to setup ssh login without password for any number of reasons like remote file/commands execution, initiating backups with SCP, etc. In this tutorial, we will learn to setup ssh login without password by using ssh public-private key-based authentication.

For this to work, we will first have to create ssh keys on one server, named SERVER A & then will copy the created public key to another Linux server, named SERVER B. The public key is copied into the file located in a user’s ssh directory i.e. ‘/home/user/.ssh/authorized_keys’.

Recommended Read: Simple guide to install POSTGRESQL on Centos/RHEL

Also Read: Simple guide to install POSTGRESQL on Ubuntu

Let’s discuss the process to create password less ssh authentication,

Setup ssh login without password

1- Login to SERVER A, and then run the following command to create ssh keys,

$ ssh-keygen -t rsa

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:

As mentioned above two files named ‘id_rsa’ & ‘id_rsa.pub’ will be created in ‘/home/user/.ssh’ directory. We need to copy the public key ‘id_rsa.pub’ to SERVER B.

2- You can use two methods to copy the public key to SERVER B, either 

  • You can copy the content of public key from SERVER A & copy it inside authorized_keys located inside the folder ‘/home/user/.ssh’,

$ cat ~/.ssh/id_rsa.pub | ssh user@remote-host(SERVER B) “cat >> ~/.ssh/authorized_keys” 

  • Or we can execute the following command to copy the public file contents from SERVER A to SERVER B,

$ ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote-host(SERVER B)

That’s it, we have now setup ssh login without password, but before we test it out we must make sure the permissions to files and folders are correct, i.e.

$ chmod 600 ~/.ssh/authorized_keys 

$ chmod 700 ~/.ssh/

3- Next, we can setup ssh login without password, 

$ ssh user@remote-host(SERVER B)

We can now access the SERVER B from SERVER A without it asking for password. We now end this tutorial, please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.