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) | Cause | Fix |
|---|---|---|
Invalid user anna from ... | Username doesn’t exist (typo?) | getent passwd anna |
Failed password for anna | Wrong password | sudo passwd anna |
Authentication refused: bad ownership or modes for directory /home/anna | ~ or ~/.ssh writable by others | see Key permissions below |
Connection closed by authenticating user anna ... [preauth] with Permission denied (publickey) on the client | No matching key, or password login disabled | check authorized_keys, see below |
User anna from ... not allowed because not listed in AllowUsers | AllowUsers / AllowGroups in sshd config | add the user or group |
User anna not allowed because account is locked | Account locked | sudo usermod -U anna |
pam_unix(sshd:account): account anna has expired | Account or password expired | sudo chage -l anna, sudo chage -E -1 anna |
Login succeeds but closes right away (This account is currently not available.) | Shell is nologin or false | sudo usermod -s /bin/bash anna |
pam_faillock(...): Consecutive login failures | Locked after too many failures (only if pam_faillock was enabled) | sudo faillock --user anna --reset |
| Nothing at all appears | Request never reaches sshd | firewall, 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
| Message | Cause | Fix |
|---|---|---|
anna is not in the sudoers file | Not in group sudo | sudo usermod -aG sudo anna, then log in again |
| Still not working after adding | Old session | Check with id: if sudo is missing, log out and in |
sudo: unable to resolve host srv01 | Hostname missing in /etc/hosts | add 127.0.1.1 srv01 |
syntax error in sudoers | Broken 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.