SSH and journald
How the journal is read
ipfence runs journalctl --follow --output=json with the matches
_COMM=sshd, _COMM=sshd-session and _COMM=sshd-auth. OpenSSH 9.8 moved
session handling into sshd-session and 10.0 added sshd-auth, so matching only
sshd would miss events. /var/log/auth.log is not used; fresh Debian 12 and
later systems may not have it.
Which entries are trusted
Any local user can write a journal line that looks like sshd. Fields beginning
with _ are filled in by journald and cannot be chosen by the sender. An entry
counts only if:
_COMMis one of the three sshd names, and_UIDis 0, and- if
_EXEis present, it is an sshd binary in a system directory (/usr/sbin,/usr/lib/openssh,/usr/lib/ssh,/usr/libexec/opensshand similar), and _EXEidentifies it, or_SYSTEMD_UNITis a configured unit (including per-connection instances such assshd@…service).
SYSLOG_IDENTIFIER is ignored. Entries that look like failures but fail these
checks are counted as journal.untrusted. An OpenSSH installed somewhere unusual
(for example under /opt or /nix/store) will be counted there and not acted on.
Which messages count
Each counts once toward the threshold (default 5 in 10 minutes).
| Message | High confidence |
|---|---|
Failed password for <user> from <addr> port <n> ssh2 |
no |
Failed password for invalid user … |
yes |
Invalid user <user> from <addr> [port <n>] |
yes |
User <user> from <addr> not allowed because …AllowUsers / DenyUsers / AllowGroups / DenyGroups / not in any group |
yes |
error: PAM: Authentication failure for <user> from <addr> (keyboard-interactive) |
only for "illegal user" |
A login attempt for a nonexistent account logs both "Invalid user" and "Failed password", so it scores twice.
Deliberately ignored: successful logins; public key failures (someone with
several keys in an agent produces them legitimately); none method failures;
"Connection closed" and "maximum authentication attempts" notices; pam_unix
lines (they would count the same failure again); and the paired
Failed keyboard-interactive/pam line. A server that only allows public keys
still reports invalid user names.
User names are hostile input
A user can log in as x from 6.6.6.6 port 22 ssh2. Patterns are anchored at both
ends and take the last address, the one sshd appended. This case was
reproduced with a real OpenSSH 10.0 server and is in the test fixtures. User names
are never stored.
An address written as a host name (when UseDNS is on) is not parsed.
Positions and gaps
The journal cursor is saved in the same transaction as the events before it.
- On first start, only entries within the scoring window are read.
- On restart, reading resumes after the saved entry, so failures logged while the daemon was down are considered if still inside the window.
- If journald vacuumed or rotated that entry away,
journalctlsilently starts elsewhere. ipfence notices, recordsjournal.cursor_lost, and shows a notice in status: events may have been missed. - If
journalctlrejects the cursor, reading restarts from the window with the same notice. - If
journalctlexits, it is restarted with increasing delays and the reader shows its error.
JSON fields larger than 4096 bytes are omitted by journalctl; such entries are
counted as journal.no_message.
Other notes
- Recent OpenSSH has its own per-source penalties (
PerSourcePenalties). They work independently and can reduce the failures ipfence sees. - Socket activation (
ssh.socket) counts as a detected service. dropbearis detected and reported as unsupported.