Normally, we will login to the remote server using user name and password at the time of authentication.

But here, we can login to the remote server without knowing user name and password of the server using ssh keys. This will be helpful when we need to pull some information or do some task in multiple servers at a time from a particular server. This can be done in  3 simple steps.

In this example, I’m using node1 and node2 servers, will login to node2 without providing any password from node1.

Step 1 :

Generate the RSA key in node1 as a root user. Accept the default values.

[root@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <Enter>
Enter passphrase (empty for no passphrase): <Enter>
Enter same passphrase again: <Enter>
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ff:bc:21:ed:c2:03:fa:0c:1d:3e:ab:60:e6:56:fc:ee root@node1

Step 2:

Copy the file /root/.ssh/id_rsa.pub key to node2.

[root@node1 Desktop]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2

root@ramesh's password:
Now try logging into the machine, with "ssh 'root@ramesh'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Step 3 :

Now you can login to node2 from node1 as root user without providing any password.

[root@node1 Desktop]# ssh node2
Last login: Tue Nov  8 15:39:32 2016 from 192.168.123.1
[root@node2 ~]# uptime
15:42:21 up 5 days, 18:01,  2 users,  load average: 0.00, 0.00, 0.00

NO COMMENTS

LEAVE A REPLY