I'm trying to setup SSH authentication via RSA files on Ubuntu 16.04 Server.
I generated key files on my local machine, then used

ssh-add  ./id_rsa

and copied id_rsa.pub to ~/.ssh/authorized_keys then changed permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys.

It works fine for one user, I type ssh user@host on my local machine and it connects automatically without asking password. But when I do all the same steps for another user, ssh asks for a password and after three unsuccessful login attempts it writes

Permission denied (publickey,password).
  • The keys must existing the .ssh directory of each users i.e. /home/<username>/.ssh – Raman Sailopal Jan 8 '18 at 13:53
  • They do. I have the same ~/.ssh/authorized_keys file with the same permissions in both users' home directories. – Sun Tzun Jan 8 '18 at 14:22
  • 1
    Did you change ownership of the file? What do you have in sshd logfiles? – Patrick Mevzek Jan 8 '18 at 14:36

The problem was in ownership of the file. I've changed owner of ~/.ssh directory to the user, which I tried to login as, and passwordless access began to work.

| improve this answer | |
  • you should accept your own answer – Kiwy Jan 8 '18 at 16:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.