If you want to login remote host B from local host A in background without password:
use
1) ssh-keygen -t rsa in local host A
2) cat $HOME/.ssh/id_rsa.pub | ssh username@B 'cat >> .ssh/authorized_keys && echo "Key uploaded successfully."'
if you have issue like below by: ssh -vvv B
...
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
usename@B's password:
...
The solution to this issue:
I have found a solution. There was an issue in permissions.
/home/username
on remote machine was granted all permissions, but for key based auth it can be set to 755