How to enable ssh login without entering password

Assume that you are a user "aliceA" on hostA, and wish to ssh to hostB as user "aliceB", without entering her password on hostB. You can follow this guide to enable ssh login without entering a password.

First of all, you need to be logged in as user "aliceA" on hostA.

Generate public/private rsa key pair by using ssh-keygen. The generated key pair will be stored in ~/.ssh directory.

$ ssh-keygen -t rsa

Then, create ~/.ssh directory on aliceB account at the destination hostB by running the following command. This step can be omitted if there is already .ssh directory at aliceB@hostB.

$ ssh aliceB@hostB mkdir -p .ssh

Finally, copy the public key of user "aliceA" on hostA to aliceB@hostB to enable password-less ssh.

$ cat .ssh/ | ssh aliceB@hostB 'cat >> .ssh/authorized_keys'

From this point on, you no longer need to type in password to ssh to aliceB@hostB from aliceA@hostA.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *