SSH (Secure SHELL) is an open-source and most trusted network protocol that is used to login to remote servers for the execution of commands and programs. It is also used to transfer files from one computer to another computer over the network using a secure copy (SCP) Protocol.
In this post, we will show you how to create a password-less authentication between servers. In this example, we are going to set up SSH password-less automatic login from server 192.168.1.57 as user geek to 192.168.1.59 with user admin. First login to 192.168.1.57 as user geek and create a public keys using ssh-keygen command.
Here are the key pairs, which were created with the ssh-keygen command.
$ ll .ssh
Now let us copy the public key to the 192.168.1.59 for the admin user. Run the following command to copy the public key to the destination server.
First create .ssh directory on 192.168.1.59 server or if you run ssh-keygen command as admin user it will create the directory and authorized_keys file. Here i am going to create the directory.
$ ssh firstname.lastname@example.org mkdir -p .ssh email@example.com's password:
Now copy the public key using the following command.
$ cat id_rsa.pub | ssh 192.168.1.59 'cat >> ~admin/.ssh/authorized_keys && echo "copied"' firstname.lastname@example.org's password: copied
Now set the correct permission for .ssh directory and .ssh/authorized_keys using the following command.
$ ssh email@example.com "chmod 700 .ssh; chmod 640 .ssh/authorized_keys" firstname.lastname@example.org's password:
Now test the login, You would be able to login from 192.168.1.57 as geek to 192.168.1.59 as admin without any password.
$ ssh email@example.com
That’s all about it. I hope you like it.