Associating ssh public key with user account

ssh

How do I associate an ssh public key with a user account on the machine I connect to, so I don't have to type in the account password every time I make an ssh connection to that machine?

The machine being connected to is an older mini with Leopard installed. I assume that this is doable in Leopard, and I don't have to upgrade to Snow Leopard or Lion.

Best Answer

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.