The meaning of SSH is Secure Shell or Secure Socket Shell. It is a cryptographic network protocol that mainly provides a secure way to connect a remote server in an unsecured network such as the internet. There are various authentication mechanisms to connect the remote server using SSH login. The two most popular mechanisms are password-based authentication and another is password-less key-based authentication.
In this article, you will learn how to set up an SSH-key based authentication and connect to the Linux server without entering a password.
Environment Details
We will be taking two Linux servers having Ubuntu Linux installed on both of them. IPs of both of the systems are given below.
SSH Client : 192.168.0.2 SSH Remote Host : 192.168.0.5
In this example, we will set up an SSH passwordless connection from the SSH Client 192.168.0.2 using user tutorialsbook to the SSH Remote Host 192.168.0.5 with user priyam.
Passwordless SSH Login
The following steps describe the process of setting up an SSH passwordless connection in a Linux server.
1) Create Authentication SSH-key on SSH Client (192.168.0.2)
In the very first step, log in to the SSH Client 192.168.0.2 using the user-id tutorialsbook and generate a pair of keys using the following commands.
ssh-keygen -t rsa
2) Create .ssh Directory on SSH Remote Host (192.168.0.5)
Using password-based SSH, connect to the SSH Remote Host 10.209.0.5 using priyam as a user and create a .ssh
directory under it. You can use the following command.
ssh priyam@192.168.0.5 mkdir -p .ssh
3) Upload Generated Public Key to 192.168.0.5
Now, again using the password-based SSH connection from the Client 192.168.0.2 sends the newly created public key (id_rsa.pub
) to the server 192.168.0.5 under priyamâs .ssh
directory as a file name authorized_keys.
cat .ssh/id_rsa.pub | ssh priyam@192.168.0.5 'cat >> .ssh/authorized_keys'
4) Set permissions on 192.168.0.5
There may be different versions of SSH available on different servers. So it is better to set the correct permission on the SSH Remote Host 192.168.0.5. we need to set permissions on .ssh
directory and authorized_keys
file as below.
ssh sheena@192.168.0.11 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
5) Login from 192.168.0.2 to 192.168.0.5 Server without Password
All done. From now onwards, you can log in to the server 192.168.0.5 using the user priyam from the client 192.168.0.2 as tutorialsbook user without a password.