SSH without password

I don’t mean to break new ground here, but for one or another reason it took me a while a couple of times to figure out why it didn’t work. There’s a huge amount of posts out there that describe how to setup SSHing to your server without a password, which have different sets of steps to make it work. This one seems to work for me (figured by trial and error):

On your server you need to make sure that ~/.ssh dir exists. Then make sure that the permissions are correct:

$ chmod go-w ~/
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys

Then you need to generate an RSA key unless you already have it:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.

So now you have the key generated in ~/.ssh/id_rsa, and the filnal step is to copy the generated key to the server. I use Ubuntu and do it this way:

ssh-copy-id -i ~/.ssh/id_rsa.pub username@host

At this point you should be all set. Try to ssh to the server and it won’t prompt for a password.

Update: There’s a really neat feature (thanks, Dan) that let’s you create ssh aliases, so you could do “ssh production” instead of “ssh user@production.host.com”. Aliases can be specified in ~/.ssh/config like this:

$ cat /home/eugene/.ssh/config 
Host production
HostName production.host.com
User user

Host staging
HostName staging.host.com
User user

This is a nice addition to the ablility to ssh without passwords.