In this article, you will learn, how to setup passwordless ssh login

SSH stands for Secure Shell. And, It authorizes to access remote connections between two systems. It uses a cryptographic network protocol for secure connections. As a result, you can manage systems, copy, or transfer files on a remote server securely.

There are two most popular authentication mechanisms. Firstly, passwords based authentication. Secondly, public key-based authentication.

Preconditions

  • A local server and a remote server
  • You must log-in with a root user or a user with sudo privilege to make the changes.
  • SSH access to a remote server via command line.

Lab settings

For this lab, we are going to use two computers. So, you can find the below information useful for the setup.

Setup for ssh local server

  • Operating system: CentOS/RHEL/Ubuntu/Debian (It can be any, but I’m using CentOS 8)
  • Hostname: server.linuxgurus.local
  • IP address: 192.168.43.10

Setup for ssh remote server

  • Operating system: CentOS/RHEL/Ubuntu/Debian (It can be any, but I’m using CentOS 8)
  • Hostname: remote.linuxgurus.local
  • IP address: 192.168.43.20

Note: In this tutorial, I will use the root user and 192.168.43.10 IP address. You can replace it with your username and IP address of your system.

Step 1: Checking for existing ssh key

So, you have to check for any existing ssh key on your local server. Because, if you have an existing ssh key then you have to overwrite. So, use the below command to verify it.

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

After running this command, if you find any existing key then you can take a backup of that existing keys or you can overwrite that keys.

If the output tells you there are no such files, move on to the next step, which shows you how to generate SSH keys.

Checking for existing ssh key

Step 2: Generating the ssh key pair

Firstly, let’s generate an ssh key pair on the local server on which you are working now. So, use the below command to generate the key pair.

ssh-keygen

Secondly, It will ask for the location to save the key pair. So, default is ok, no need to change it. Only, press the enter key.

ssh-keygen and it’s location

Thirdly, it will ask for passphrase means any additional password. This is not necessary for passwordless login. So, just press the enter key twice.

asking for passphrase

Lastly, it will give you the information about file location and key fingerprint. You can see in the below picture.

Generating the ssh key pair

Now, you can verify it using the below command.

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

You can see in the below picture the location of the public key and private key.

Step 3: Uploading the public key to the remote server

So, this is the time to upload the public key to the remote server using the ssh-copy-id command. And, this is the secure and the best option to upload the public key.

ssh-copy-id root@192.168.43.20

Here, you can change the username root with your chosen name and you can change the IP address 192.168.43.20 as per your remote server or system IP address.

Uploading the public key to the remote server

Step 4: Log in to the server without password

In conclusion, you have generated the ssh key pair and you have uploaded the public key to the remote server. So, now you can connect your remote server without providing any password.

You can verify it by using the below command.

ssh [remote_username]@[server_ip_address]

For example, as per our lab setup

ssh root@192.168.43.20

And, you can see in the picture, it is not asking for password.

Log in to the server without password

Conclusion

In this tutorial, you learn about How to setup passwordless ssh login. In conclusion, you can log in without a password. So, I hope, you understand but if you have any questions, you can ask in the comment section.

You can read more about How to install and configure OpenSSH in Linux?

Top 20 SSH interview questions and answers

How to enable ssh on Ubuntu 18.04/19.10/20.04

You can also read more about what is ssh protocol

10 Comments

  1. I value the blog post. Want more.

  2. After looking at a number of the blog posts on your web page, I really appreciate your way of writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the near future. Please check out my website as well and tell me your opinion.

  3. Everything is very open with a precise clarification of the challenges. It was definitely informative. Your website is useful. Many thanks for sharing!

  4. Hello, after reading this remarkable post i am also cheerful to share my experience here with friends.

  5. 内容翔实,谢谢分享。

  6. Im obliged for the blog post. Thanks Again. Fantastic.

  7. You made some decent points there. I looked on the internet for additional information about the issue and found most individuals will go along with your views on this website.

  8. Interesting, nicely define. thanks Guru

Leave a Reply