How to set up password less SSH in linux ?
Source: Node1 (10.20.30.1)
Target: Node2 (10.20.30.2)
From Node1 we will setup passwordless SSH to Node2 and vice verse.
1- Login to Node1 as the same user on which the password less SSH is required .
Here we are using root user .
2-Now run the ssh keygen
[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 passphrase (empty for no passphrase):
Enter same passphrase again:
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:
SHA256:qYu/TJOvB44ewNd4UU3A/kmMG1bhAJRIqnjinl9C2Cw root@node1
The key's randomart image is:
+---[RSA 2048]----+
| .o+...oo |
| .. ..... |
| .. .o . |
| . o o.o. + o |
| o o = So . O |
| o B.= o + . |
| Eo@.. |
| .B.B. |
| .ooX+. |
+----[SHA256]-----+
3-Now we will use the ssh-copy-id to installs the SSH key on target server as an authorized key. Its purpose is to provide access without requiring a password for each login
[root@node1 ]# ssh-copy-id root@10.20.30.2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.20.30.2's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@10.20.30.2'"
and check to make sure that only the key(s) you wanted were added.
4-As mentioned above now we will try to ssh the target server to check the password less ssh is working or not .
[root@node1 ]# ssh root@10.20.30.2
Last login: Wed Aug 30 18:44:41 2023 from 10.20.30.1
[root@node2 ~]# exit