Skip to content
Jens Jäger

Set up ssh key pairs

This post is part of the archive. It was written years ago, so some of the tools, versions and links may be outdated.

With ssh key pairs you can easier login to your servers.

To generate an ssh key pair you´ll need to run the following line in your terminal:

ssh-keygen -t dsa

It will ask you for location and pass phrase. You should accept the default location (~/.ssh/id_dsa.pub). For the pass phrase I usually just press return. Then the private key will have a blank pass phrase and you can login to your servers without a password. Comfort vs. security. Your choice.

After this you need to upload the public key to the server.

scp ~/.ssh/id_dsa.pub you@yourserver.com:

Finally login to the server and append the public key to authorized keys:

ssh you@yourserver.com
mkdir .ssh          # if it's not already there
cat id_dsa.pub >> .ssh/authorized_keys
rm id_dsa.pub       # cleanup

Make sure that the .ssh folder and the authorized_keys have the right permissions:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

After this, you should be able to login to the server and use scp without having to enter a password.

If you login or copy files to your servers a lot, you can setup an alias in ~/.ssh/config (on your local machine):

Host ys
HostName yourserver.com
User you