Ssh using public keys

From LinuxNewbie

To generate keys for the client, use this command. Since you want unattended login, press enter when it asks for a password.

$ ssh-keygen -t dsa

The destination machine requires an .ssh directory in the home of the user you want to login to, and that directory should be chmod 700. Here are the command to create it in the event it doesn't exist:

$ mkdir ~/.ssh
$ chmod 700 ~/.ssh

If it already exists, you can place the public key from the client without needing to login to the remote machine.

$ cat ~/.ssh/id_dsa.pub | ssh SERVERB 'sh -c "cat - >>~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"'

Notice the >> to APPEND to the authorizes keys. If you do not append you will lose the ability to login if you have added other public keys. Most tutorials that scp directly overwrite the authorized_keys.