Passwordless ssh

28 Sep 2009

You want to use ssh to connect to other computers, but you don’t want to keep typing your password.

On the local computer: if don’t have them already, generate your private/public pair of keys

user@local ~$ ssh-keygen -t rsa

Accept all the default options and when asked for a passphrase just press enter.

This should create the two files

~/.ssh/id_rsa     - your private key
~/.ssh/id_rsa.pub - your public key

On the remote computer: if it doesn’t exist already, create the ~/.ssh directory

user@remote ~$ mkdir ~/.ssh
user@remote ~$ chmod 700 ~/.ssh

Finally append the contents of the local file ~/.ssh/id_rsa.pub to the remote file ~/.ssh/authorized_keys. For example, on the local computer:

user@local ~$ scp ~/.ssh/id_rsa.pub user@remote.example.com:.ssh/my_new_key

And then on the remote computer:

user@remote ~$ cat ~/.ssh/my_new_key >> ~/.ssh/authorized_keys
user@remote ~$ rm ~/.ssh/my_new_key