Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
If you have never set up an authorized_keys on the remote host, you can save a little bit of time by simply doing; scp ~/.ssh/id_dsa.pub user@remotehost:~/.ssh/authorized_keys –  Jason Salaz Aug 15 '11 at 20:02
1  
@VxJasonxV: Right, but now that I think about it there's even a way to collapse all the bullet-points into one line, even with appending: ssh user@targetmachine 'cat >>~/.ssh/authorized_keys' <~/.ssh/id_dsa.pub But I think the step-by-step solution in my answer is easier to understand. –  DarkDust Aug 15 '11 at 21:35
    
It is, by far :). –  Jason Salaz Aug 16 '11 at 0:37
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.