The basis of using ssh without typing your password is public key based authentication. You need to generate a pair of public/private keys for this.
1. Firstly, generate your public/private keys using ssh-keygen
#ssh-keygen -t rsa
You must use the -t option to specify that you are producing keys for SSHv2 using RSA. This will generate your id_rsa and id_rsa.pub in the .ssh directory in your home directory. You can either opt for a pass phrase or simply type enter. It is recommended to use a pass phrase.
2. Now copy the id_rsa.pub to the .ssh directory of the remote host you want to log on to as authorized_keys2 .
If you have more than one host from which you want to connect to the remote host, you need to add the local host’s id_rsa.pub as one line in the authorized_keys2 file of the remote host, i.e., you can have more than one entry. Also, you need to ‘chmod 644 authorized_keys2‘ to make it unwritable to everybody apart from the user.
You are basically telling the sshd daemon on the remote machine to encrypt the connection with this public key and that this key is authorized for version 2 of the ssh protocol. You can use something secure like scp for this copying.
#scp /home/username/.ssh/id_rsa.pub username@domainname
:/home/username/.ssh/authorized_keys2
Now you can ssh without having to type in your password.
Here is a small test :
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/techfiz/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/techfiz/.ssh/id_rsa.
Your public key has been saved in /home/techfiz/.ssh/id_rsa.pub.
The key fingerprint is:
a5:b5:89:00:fa:c0:0d:33:e2:e8:0d:88:d6:7c:00:cd [email protected]
$ scp /home/techfiz/.ssh/id_rsa.pub
[email protected]:/home/techfiz/.ssh/authorized_keys2
[email protected]′s password:
id_rsa.pub 100%
|*************************************|
231 00:00
$ ssh -l techfiz 192.168.0.11
$



