Suppose you have two machines: A and B. A is your work machine, you do most of your work on it. But B is a little special (e.g., connected to some specific hardware) that you need to ssh on it or copy some file from A to B from time to time. Here is the way that you can get rid of entering passwords every time you do ssh/scp.
First, on machine A, generate a DSA key pair:
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (YOUR_HOME/.ssh/id_rsa): # press ENTER here to accept the default filename Enter passphrase (empty for no passphrase): # press ENTER here to use no passphrase, otherwise, you still need # to enter this passphrase when ssh Enter same passphrase again: # press ENTER here Your identification has been saved in $HOME/.ssh/id_rsa. Your public key has been saved in $HOME/.ssh/id_rsa.pub. The key fingerprint is: ..... (omited)
Then, change the access mode of .ssh directory
$ chmod 775 ~/.ssh
Then append the content of your just generated
id_rsa.pub to the
$HOME/.ssh/authorized_keys file on machine B:
# copy the id_rsa.pub file to host B $ scp ~/.ssh/id_rsa.pub b@B:. # login to B $ ssh b@B # append the content to authorized_keys $ cat id_rsa.pub >> .ssh/authorized_keys
Finally, ssh on to B and change the access mode of the file
This is optional, maybe you don't need to do this if you can already ssh
without entering password.
$ ssh b@B $ chmod 700 .ssh $ chmod 640 ~/.ssh/authorized_keys
Depend on your version of ssh, you may also need to do the following:
$ ssh b@B $ cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys2
That it! Enjoy!