oebfare

Login to SSH without a password

I connect to many different servers each day and hate having to type my credentials. The obvious solution is to use a public/private key to make authentication much easier. Let me outline what I did to accomplish this.

First, create yourself a public/private key pair:

ssh-keygen -t rsa

This will prompt you for a location to save the key. By default it will save it at ~/.ssh/id_rsa. It will also prompt you for a passphrase. You can leave this blank for passwordless login, but I recommend against that. What this can enable you to do is keep all your passwords consistent across the servers you connect to. The reason why I titled this article as password-less is because OS X 10.5 will use Keychain to store the password for you.

Now you will need to move your public key to the server you would like to use it with. This can be done all in one command:

cat ~/.ssh/id_rsa.pub | ssh user@server "cat >> .ssh/authorized_keys"

Basically, you need to get the contents of the ~/.ssh/id_rsa.pub file into the ~/.ssh/authorized_keys file on the server you choose to use it with. You can upload your public key to as many different servers as you like.

I also want to make note that the ~/.ssh directory on your server must be chmod'ed with 700 and owned by you. This will normally be taken care of for you, but in the event you have any weird problems, be sure to check that.

Entry Details

Published: Jan 29, 2008 at 9:58 AM

© 2007 - 2008 Brian Rosner