Passwords are a risky authentication method while communicating remotely. A better way is using SSH.

SSH is a network protocol to securely access remote servers. It employs following techniques:

  • Asymmetric encryption: to authenticate the client using private/public keys.
  • Symmetric encryption: once the authentication is done, a shared session key is generated using Diffie-Hellman key exchange algorithm which is used to encrypt/decrypt all communciation.
  • Hashing: to maintain data integrity.

To login to remote server using SSH without passwords, the client needs to generate a keypair and copy the public key to server’s authorized_keys.

  1. Generate private/public keypair on the client machine
1
ssh-keygen -t rsa
  1. Copy the public key from client machine to remote host
1
2
3
ssh-copy-id username@remote_host_ip
# alternate command if ssh-copy-id is not available
cat ~/.ssh/id_rsa.pub | ssh username@remote_host_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Now forget the password and simply login using ssh 'username@remote_host_ip'.