Saturday, 24 November 2012

How to Set Up a Password-less SSH Login

First, on the local machine you will want to generate a secure SSH key:
ssh-keygen

Walk through the key generator and set a password, the key file by default goes into ~/.ssh/id_rsa

Next, you need to copy the generated key to the remote server you want to setup passwordless logins with, this is easily done with the following command string but you can use scp if you’d prefer:
cat ~/.ssh/id_dsa.pub | ssh user@remotehost 'cat >> ~/.ssh/authorized_keys'

This command takes the generated SSH key from the local machine, connects to the remote host via SSH, and then uses cat to append the key file to the remote users authorized key list. Because this connects with SSH to the remote machine you will need to enter the password to use this command.
Finally, confirm that you can now login to the remote SSH server without a password:
ssh user@remotehost.com

Assuming initial setup went as intended, you will connect to the remote machine without having to log in.