Associating ssh public key with user account

Solution 1:

First, you create a public and private key (if you haven't done so already) on the machine from which you want to login:

ssh-keygen -t dsa

You only need to do this if there isn't already a ~/.ssh/id_dsa.pub file.

On Linux, there's the ssh-copy-id helper. On Mac, you need to copy the public key by hand:

  • Copy the generated public key to the target machine:

    scp ~/.ssh/id_dsa.pub user@targetmachine:myPublicKey.pub

  • Login to the target machine:

    ssh user@targetmachine

  • Append the public key to the authorized keys:

    cat myPublicKey.pub >>.ssh/authorized_keys

  • You can now delete the copied key:

    rm myPublicKey.pub

  • Done. You should now be able to login to your target machine without the need to enter a password.

Solution 2:

You should have an id_dsa.public file in your ~/.ssh folder.

Just copy that file over to the server, into ~/.ssh folder and append its contents to the authorized_keys file.

Your next login should be automatic. It can be that you're asked about the password you used to created the private key, but there's an option to store that password into your keychain.