ubuntu, updated

Debugging login problems

Someone can't log in via SSH or sudo: a step-by-step checklist with the log lines and fixes for the usual causes.

Step 1: watch the log while the user tries

On the server (as admin, in a working session):

sudo journalctl -u ssh -f        # SSH logins
# or everything auth related:
sudo tail -f /var/log/auth.log

Let the user try again. The line that appears tells you the reason. On the client side, more detail comes from:

ssh -v anna@server               # -vvv for even more

Step 2: match the log message

Log message (auth.log / journal)CauseFix
Invalid user anna from ...Username doesn’t exist (typo?)getent passwd anna
Failed password for annaWrong passwordsudo passwd anna
Authentication refused: bad ownership or modes for directory /home/anna~ or ~/.ssh writable by otherssee Key permissions below
Connection closed by authenticating user anna ... [preauth] with Permission denied (publickey) on the clientNo matching key, or password login disabledcheck authorized_keys, see below
User anna from ... not allowed because not listed in AllowUsersAllowUsers / AllowGroups in sshd configadd the user or group
User anna not allowed because account is lockedAccount lockedsudo usermod -U anna
pam_unix(sshd:account): account anna has expiredAccount or password expiredsudo chage -l anna, sudo chage -E -1 anna
Login succeeds but closes right away (This account is currently not available.)Shell is nologin or falsesudo usermod -s /bin/bash anna
pam_faillock(...): Consecutive login failuresLocked after too many failures (only if pam_faillock was enabled)sudo faillock --user anna --reset
Nothing at all appearsRequest never reaches sshdfirewall, wrong IP/port, sshd down: systemctl status ssh, sudo ss -tlpn | grep :22

Key permissions

SSH silently ignores keys if the permissions are too open:

sudo chown -R anna:anna /home/anna/.ssh
sudo chmod 755 /home/anna                     # or 750; never group/other-writable
sudo chmod 700 /home/anna/.ssh
sudo chmod 600 /home/anna/.ssh/authorized_keys

Also check that the key in authorized_keys is on one line and is the user’s public key (.pub).

Check the effective SSH config

The config is spread over /etc/ssh/sshd_config and /etc/ssh/sshd_config.d/*.conf. Instead of reading all files, ask sshd what it actually uses:

sudo sshd -T | grep -Ei "passwordauthentication|permitrootlogin|allowusers|allowgroups|pubkeyauthentication|port"

After changing the config: test it, then reload.

sudo sshd -t && sudo systemctl reload ssh

Warning: Keep your current SSH session open while you change SSH settings, and test in a second session. If you lock yourself out, the open session lets you fix it.

sudo doesn’t work

MessageCauseFix
anna is not in the sudoers fileNot in group sudosudo usermod -aG sudo anna, then log in again
Still not working after addingOld sessionCheck with id: if sudo is missing, log out and in
sudo: unable to resolve host srv01Hostname missing in /etc/hostsadd 127.0.1.1 srv01
syntax error in sudoersBroken file in /etc/sudoers.d/Boot into recovery mode (root shell), or pkexec visudo if polkit is installed

Failed sudo attempts are logged: sudo journalctl _COMM=sudo --since today.

§ home
~/knubertus/home/
1,1 Top