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– lord.garbage2014-10-22 12:05:04 +00:00Commented Oct 22, 2014 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– Tman2016-12-08 08:01:05 +00:00Commented Dec 8, 2016 at 8:01
4 Answers
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 .sshreplaceuserbwith your current user. i didchown -R userb:userb .ssh/authorized_keysjust in case too. Really helpful answer!!IvRRimUm– IvRRimUm2018-06-23 20:25:41 +00:00Commented Jun 23, 2018 at 20:25 -
less /var/log/auth.logshown interesting stuff!Authentication refused: bad ownership or modes for directory /home/piThis was not flagged anywhere inssh -vvv, bad debug info from SSH it's always a headache.Rho Phi– Rho Phi2021-06-01 10:02:31 +00:00Commented Jun 1, 2021 at 10:02
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 accountStuart Cardall– Stuart Cardall2018-03-02 10:45:36 +00:00Commented Mar 2, 2018 at 10:45
-
..and now you have two problems. hope that password is secure.300D7309EF17– 300D7309EF172018-12-13 20:37:41 +00:00Commented Dec 13, 2018 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 /homeitsafire– itsafire2018-08-10 13:41:20 +00:00Commented Aug 10, 2018 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– ryanoshea2020-06-06 19:32:49 +00:00Commented Jun 6, 2020 at 19:32
-
Instead of
StrictModes nofirst try to set permissions 700 to your home folder chmod 700 /home/user Also check this article enter link description hereVladimir Rybinsky– Vladimir Rybinsky2021-05-29 10:26:40 +00:00Commented May 29, 2021 at 10:26 -
Sadly this would be the only solution but is not secure enough for my use-casetnfru– tnfru2022-09-23 11:34:39 +00:00Commented Sep 23, 2022 at 11:34
-
weird thing about ssh config - I found some elements just will not kick on even if you restart the daemon and only a full restart to the main runlevel target (or a reboot) would fix it, I did that and it was golden.osirisgothra– osirisgothra2025-03-27 18:10:06 +00:00Commented Mar 27 at 18:10
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).