SSH-RSA Key – Unable to Login with SSH-RSA Key

authenticationkey-authenticationsshsshd

This post is following this question : Authentication refused: bad ownership or modes for file /var/git/.ssh/authorized_keys .

The issue as exposed there is
solved (about files modes of the .ssh folder.

But an other issue persists so I create a new question :

When I try to login (with verbose options), all seems to work fine but at the end, here is what happened :

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/remi/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/remi/.ssh/id_dsa
debug1: Trying private key: /home/remi/.ssh/id_ecdsa
debug1: Trying private key: /home/remi/.ssh/id_ed25519
debug2: we did not send a packet, disable method
debug1: Next authentication method: password

I don't understand because these lines seems to be a non-sense for me :

  • we sent a publickey packet, wait for reply
  • we did not send a packet, disable method

Best Answer

You will get this behaviour if the file mode of the user's home directory on the destination host is not set correctly. It's not just the mode of the .ssh directory that has to be correctly set!

ssh to the host and give your password to login, then

chmod 755 ~
logout

Then ssh again and assuming you have everything else set up correctly (see the other answers), you should be able to login.

This is what it looks like when the home directory is wide open (777). Note that it doesn't try the rsa key:

ssh -v user@host
...
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/iwoolf/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/iwoolf/.ssh/id_dsa
debug1: Trying private key: /home/iwoolf/.ssh/id_ecdsa
debug1: Trying private key: /home/iwoolf/.ssh/id_ed25519
debug1: Next authentication method: password
...

Then with the home directory permissions set correctly (755):

ssh -v user@host
...
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/iwoolf/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Related Question