Skip to content

sshd-logging-debug: OpenSSH authentication debugging and resolution

Lead paragraph: When OpenSSH authentication goes silent without obvious cause, enabling detailed logging is the fastest path to diagnosis. Understanding what happens at the sshd level lets you resolve the issue in minutes, not hours. This note shows how to enable LogLevel DEBUG3, locate records in the system, and decode typical access-rejection errors without wasting time on Google searches.

Enabling LogLevel DEBUG3 in sshd_config

By default LogLevel is set to INFO, which records only basic connection and disconnection events. DEBUG3 exposes the full event stream: from handshake initiation through key checks and PAM modules. Enabling it requires editing the config and restarting the daemon.

sed -i 's/^#*LogLevel .*/LogLevel DEBUG3/' /etc/ssh/sshd_config
systemctl restart sshd

After debugging, revert the level to INFO or VERBOSE, as DEBUG3 generates significant data and can impact performance under high load.

Tip

If a daemon restart is unavailable, sending USR1 to the sshd process can activate debugging, but full effect comes only with restart using the new config.

Log entries appear in journald (when SyslogFacility is AUTHPRIV) and in /var/log/auth.log on classic distributions.

Searching and Reading Logs in journald and auth.log

Real-time log viewing:

journalctl -u sshd -f

Session‑specific records from the last few minutes:

journalctl -u sshd --since "5 minutes ago" | grep -i "DEBUG\|Failed\|pam\|auth"

On systems without systemd or in containers, logs may reside in /var/log/auth.log:

tail -n 200 /var/log/auth.log | grep -i "sshd\|auth"

With DEBUG3, focus on lines starting with Authentication, pam, Accepted, Failed. They contain the rejection reason and the username.

Decoding Common Errors: invalid user, pam, authorized_keys

Typical log lines and their meaning:

Log lineMeaningTypical cause
Failed password for invalid user root from 10.0.0.1 port 54322 ssh2authUser does not exist in /etc/passwd or is locked out
pam_unix(sshd:auth): authentication failurepamWrong password, account lockout expired, PAM configuration
Authorization failed for user deployauthzauthorized_keys lacks a matching key, incorrect permissions
Did not receive identification stringtransportClient did not send banner, old protocol, banner issue
Key type RSA1 not allowedkexClient attempts obsolete key; KexAlgorithms may block

Note the suffixes ,1 or ,2 after the reason — they indicate the specific check step (password check, key check, etc.).

Scenario: Locked-Out User

Account lockout via passwd -u or expired lockout time appears in the log as Permission denied (account locked). Status check:

passwd -S username

LK in the output field means the account is locked. In /etc/shadow this shows as ! before the password hash.

Unlocking:

passwd -u username

Or remove the lock flag directly in the shadow file (requires root):

sed -i 's/^username:!: /^username: /' /etc/shadow

After changes, restart sshd or send SIGHUP if the config permits.

Scenario: Wrong Password

Failed password for admin from 10.0.0.1 port 49152 ssh2 without invalid user means the user exists but password authentication failed. Causes:

  • Typo or CapsLock
  • Password change not yet propagated to sshd (rare, usually instant)
  • PAM auth settings requiring additional conditions (e.g., pam_tally2 blocks after N failures)

Reset the pam_tally2 counter (if installed):

tally2 --user=admin --reset

Check password policy:

chage -l admin

Scenario: Expired Key Life

OpenSSH does not expire user keys by default, but CA‑signed keys have valid-after/valid-before validity. If access is rejected due to a key, check:

CA key validity:

ssh-keygen -L -f /etc/ssh/trusted_user_ca_key

~/.ssh/authorized_keys rights and ownership:

ls -la ~/.ssh/
# Expected: drwx------ 2 user user 4096 date authorized_keys
# Error: permissions are too open

The authorized_keys line must start with the key type (ssh-rsa, ecdsa-sha2-nistp256, etc.), followed by base64 data and a comment. Extra spaces or line breaks break parsing.

Diagnose via ssh:

ssh -vvv user@host 2>&1 | grep -i "key\|auth"

Output shows which key was proposed and whether it was accepted. If the key is rejected, verify PubkeyAuthentication yes, IdentitiesOnly yes (when multiple keys exist in ssh-agent), and no symlinks in the ~/.ssh/ chain.

Warning

When working with DEBUG3, avoid storing verbose logs in production for extended periods. Shorten retention or filter by IP/user immediately after data collection.