If you regularly ssh and scp between *nix-based machines (Mac OS X/Linux), this will save you the time and effort of entering your passord every time. Let's say you want to ssh from host "A" to host "B". Here's how you set it up.

First log into host A and generate a pair of authentication keys. Note that this step only has to be performed ONLY ONCE on the host you want to SSH from, and you can copy the public key to any number of remote hosts. Do not enter a passphrase at the prompt (leave blank).

 a@A:$ ssh-keygen -t rsa
 Generating public/private rsa key pair.
 Enter file in which to save the key (/Users/a/.ssh/id_rsa): 
 Created directory '/Users/a/.ssh'.
 Enter passphrase (empty for no passphrase): 
 Enter same passphrase again: 
 Your identification has been saved in /Users/a/.ssh/id_rsa.
 Your public key has been saved in /Users/a/.ssh/id_rsa.pub.
 RSA key fingerprint is: e0:e5:29:49:c8:00:32:3f:18:5f:56:69:88:d8:90:45
 a@A:$

Next you must create a directory called ".ssh" on the remote host "B". If this directory already exists, you can skip to the next step.

 a@A:$ ssh b@B
 Password:
 b@B:$ mkdir .ssh
 b@B:$ exit
 a@A:$ 

Now copy the file ".ssh/id_rsa.pub" from host A to a file called ".ssh/authorized_keys" on the remote host "B". If the authorized_keys file already exists on host "B", the following step will append the new public key file to the end of the existing authorized_keys.

 a@A:$ cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
 b@B's password: 

From now on you can log into B as b from A as a without password:

 a@A:$ ssh b@B
 b@B:$ 

Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640