Introduction
Passwordless SSH authentication is used when we need to configure cluster on remote server or for database configuration. To login via SSH without password we have to use ssh-keygen, ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.
Step 1: Create public and private keys using ssh-keygen
Firstly, we generate authentication keys using the following commands. In our case there are two server i.e. sun1 and sun2, we will generate public and private keys on both solaris machines.
sun1# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in //.ssh/id_rsa.
Your public key has been saved in //.ssh/id_rsa.pub.
The key fingerprint is:
d6:80:39:44:9e:c4:0f:78:18:f7:9c:eb:f4:64:96:c4 root@sun1
Step 2: Create public and private keys using ssh-keygen on other server
Now generate public and private keys using ssh-keygen on other server.
sun2# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in //.ssh/id_rsa.
Your public key has been saved in //.ssh/id_rsa.pub.
The key fingerprint is:
31:0c:f9:6a:c1:c2:0e:cb:f0:3c:07:76:28:fa:a2:f4 root@sun2
Step 3: Copy the public key to other machine
Next step is to copy the public key (.pub) file to other machine (sun2).
sun1# cd /.ssh
sun1# scp -r id_rsa.pub sun2:/.ssh/authorized_keys
Password:
id_rsa.pub 100%|*****************************************************************| 219 00:00
Step 4: Copy the public key to remote machine
Now also copy the generated public key (.pub) to remote machine (sun1).
sun1# cd /.ssh
sun1# scp -r id_rsa.pub 172.25.26.101:/.ssh/authorized_keys
Password:
id_rsa.pub 100% |********************************************************************************************************************| 219 00:00
Step 4: Login to remote-machine without password
Now you can freely login to remote-machine without password to sun2 server
sun1# ssh 172.25.26.101
Last login: Tue May 2 13:49:40 2017 from sun1
Oracle Corporation SunOS 5.10 Generic Patch January 2005
sun2#
All done. Enjoy Passwordless authentication on both servers.