Establishing ssh connection between two hosts in Linux

Consider two hosts A and B with user a on host A and user b on  host B. We are establishing a secure connection between these two hosts A and B for user a to login automatically without password to user b account on host B.

 

We first login on A as user a and we should generate a pair of authentication keys i.e, public and private keys. This is done as follows:
 
a@A: ssh-keygen -t rsa
 
Now we should create a directory .ssh as user b on host B.
 
a@A: ssh b@B mkdir-p .ssh
 
here it asks for b@B’s password.Enter the password.
 
Now we should copy the a’s public key to b@B:.ssh/authorized_keys.
 
a@A:cat .ssh/id_rsa.pub | ssh b@B ‘cat >> .ssh/authorized_keys
 
It will again ask for b@B’s password.Enter the password.
 
After this you can log into B as user b from A as user a without a password.
 
a@A: ssh b@B