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 a 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.


1. You are still asked for an SSH password even after enabling key authentication. In this case, check for system logs (e.g., /var/log/secure) to see if you see something like the following.

Authentication refused: bad ownership or modes for file /home/aliceB/.ssh/authorized_keys

In this case, failure of key authentication is due to the fact that the permission or ownership ~/.ssh/authorized_keys file is not correct. Typically this error can happen if ~/.ssh/authorized_keys is read accessible to anyone but yourself. To fix this problem, change the file permission as follows.

$ chmod 700 ~/.ssh/authorized_keys
Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

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.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to enable ssh login without entering password

  1. Is there any way to install ssh on ubuntu server and ssh on a remote windows server to enable login without entering a password? I am trying to find a way to have my ubuntu web server check if a file exists on a windows server and store the name of that file in a database in my ubuntu web server.

Leave a comment

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