Kevin Hatfield's Blog

Kevin's blurry train of thought……

Login via SSH Automatically

That is really not the right phrase for it. It should be something like “key-based authorization with SSH”. Or simply “publickey authorization”. Or “unattended ssh login”. But I guess you know what I mean. Here are the steps:

1. Create a public ssh key, if you haven’t one already. Look at ~/.ssh. If you see a file named id_dsa.pub then you obviously already have a public key. If not, simply create one. ssh-keygen -t dsa should do the trick. Please note that there are other types of keys, e.g. RSA instead of DSA. I simply recomend DSA, but keep that in mind if you run into errors.
2. Get your public ssh key on the server you want to login automatically. A simple scp ~/.ssh/id_dsa.pub user@yourserver.com: is ok.
3. Append the contents of your public key to the ~/.ssh/authorized_keys. Important: This must be done on the server you just copied your public key to. Otherwise you wouldn’t have had to copy it on your server. Simply issue something like cat id_dsa.pub >> .ssh/authorized_keys while at your home directory.
4. Remove your public key from the home directory on the server.
5. Done.

That’s all you need to do. I know there is a fancier way to do this, you can pipe your public key contents to the authorized_keys with just one command. But if you’re a Unix newbie it helps not to have to blindly type in commands you don’t understand.

Leave a Reply

You must be logged in to post a comment.