Scenario:

You have two servers, ServerA and ServerB – you would like ServerA to be able to SSH in to ServerB without a password. Use this simple tutorial to achieve this:

Step 1: Generate public key on ServerA

SSH in to ServerA and enter the following command. Keep pressing enter (accept the defaults) – do not enter a passphrase.ssh-keygen -t dsa

This should have generated a file, /root/.ssh/id_dsa.pub

Copy the contents of the file above:cat /root/.ssh/id_dsa.pub

Step2: Copy ServerA’s public key to ServerB

SSH in to ServerB and paste the contents from /root/.ssh/id_dsa.pub from ServerA (above) in to /root/.ssh/authorized_keys on ServerB:

If the /root/.ssh directory does not exist, create it first:mkdir /root/.ssh
vim /root/.ssh/authorized_keys

Set the required permissions on the authorized_keys file:chmod 0600 /root/.ssh/authorized_keys

Now try and SSH to ServerA from ServerB – you should not be prompted for a password. The same process can be used for other users, apart from root. If you want ServerB to have passwordless SSH access to ServerA, perform the same steps as above, but swap ServerA for ServerB the next time you do it.