I’m going to explain how to set ssh trust between two hosts. This would allow us to connect to the server without having to type the password.
1) First generate the public and private keys on the machine from where you want to log in to other machines. This can be accomplished in two ways depending on the ssh version running on the server you want to log in. I recommend using ssh version 2. Ssh version 1 has security flaws.
Type from the command line:
# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.
The key fingerprint is:
The key’s randomart image is:
+–[ DSA 1024]—-+
| o+=… |
| .+ooo.. |
| =.. o. |
| +.o. E |
| +.oS* |
| =.+ . |
| . |
This will generate a public and a private key in the ~/.ssh directory. Don’t type anything when asked for the passphrase. Now we need to copy the public key to the server we want to log in passwordless.
2) Type the following.
# scp ~/.ssh/id_dsa.pub user@remote_server:/tmp
3) Log into the remote server and copy the public key to the authorized_keys file in the ~/.ssh directory.
remote_server# cat /tmp/id_dsa.pub >> ~/.ssh/authorized_keys
That’s it. You are done. Enjoy.