Setup public key authentication between two servers

To setup the public key authentication or key based authentication, lets assume first server as server1.example.com and the second server as server2.example.com. Automated login from server1 to server2. On server1, generate the key pair: By entering the command, below output will be generated: The private key and public key is generated. Now, copy the public key /root/.ssh/id_rsa.pub to server2. Once you entered the password, the key will be copied to server2 at /root/id_rsa.pub. Now log into server2 and append the key in /root/.ssh/authorized_keys file. That’s it. Now, exit from server2 and try to login from server1 to server2 and it will login automatically. To login automatically from server2 to server1 then the key pair is generated on on server2 and the public key is copied to server1. Need Help? Checkout our plans.