I have a server, and I want to be able to SSH in with two different users. I have setup public key authentication for the first user, and it works just fine, however, I can't login with the second user. The difference between the authorized_keys file is that, the second user has two keys(both of them fail when authenticating). Both the .ssh directory and the authorized keys file have 755 permissions. The ssh client sends the key, that I want to authenticate with. What could be the problem?

  • Please show the commands for the two users and the different keys for the second user you are using to ssh into the server. – lord.garbage Oct 22 '14 at 12:05
  • Glad the above worked in your case. Besides just resetting the password. I'd advice to also have a look if you have pam_tally locking the account. pam_tally2 --user userb --reset This will reset the failed counts on the account and allow you to login. – Tman Dec 8 '16 at 8:01

First, the .ssh directory should have 700 permissions and the authorized_keys file should have 600.

chmod 700 .ssh
chmod 600 .ssh/authorized_keys

In case you created the files with say root for userB then also do:

chown -R userb:userb .ssh

If the problem still persist, then post the output from your ssh log file in your question and I'll update my answer.

For Debian:

less /var/log/auth

For Redhat:

less /var/log/secure
  • chown -R userb:userb .ssh replace userb with your current user. i did chown -R userb:userb .ssh/authorized_keys just in case too. Really helpful answer!! – IvRRimUm Jun 23 '18 at 20:25

I have found this message in /var/log/auth.log:

Oct 22 13:27:58 hagyma sshd[27420]: User userb not allowed because account is locked

I have set a password for userb with sudo passwd userb, and it unlocked the account.

  • this was the solution for a backup user created as a system account – Stuart Cardall Mar 2 '18 at 10:45
  • ..and now you have two problems. hope that password is secure. – tedder42 Dec 13 '18 at 20:37

For me, sshd was ignoring ~/.ssh/authorized_keys because /home partition was mounted in an unusual way. I tried everything, I set the correct permisions, and it worked only after modifying in sshd_config:

StrictModes no
  • This was working for me on CentOS 7. root login with public key was working, but not for users on /home – itsafire Aug 10 '18 at 13:41
  • I tried adding this to my Synology's config, and it caused sshd to fail to start. Nearly locked myself out of the server. – ryanoshea Jun 6 '20 at 19:32

I had same problem due to SELinux.

Please, configure SELinux properly (restorecon -Rv ~/.ssh) or disable it (on RedHat, you should edit /etc/selinux/config and reboot the machine or just type setenforce 0 to disable SELinux temporarily until next reboot).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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