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.garbageOct 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.– TmanDec 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 .ssh
replaceuserb
with your current user. i didchown -R userb:userb .ssh/authorized_keys
just in case too. Really helpful answer!!– IvRRimUmJun 23, 2018 at 20:25 -
less /var/log/auth.log
shown interesting stuff!Authentication refused: bad ownership or modes for directory /home/pi
This was not flagged anywhere inssh -vvv
, bad debug info from SSH it's always a headache.– Rho PhiJun 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 account Mar 2, 2018 at 10:45
-
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– itsafireAug 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. Jun 6, 2020 at 19:32
-
Instead of
StrictModes no
first try to set permissions 700 to your home folder chmod 700 /home/user Also check this article enter link description here May 29, 2021 at 10:26 -
Sadly this would be the only solution but is not secure enough for my use-case– tnfruSep 23, 2022 at 11:34
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).