Test the fail2ban sshd filter with fail2ban-regex
Count how many auth log lines the sshd filter catches before you enable a jail, then check the missed lines and how each mode changes the result.
Lines: 12 lines, 3 ignored, 6 matched, 3 missedfail2ban-regex replays a log through a filter and ends with this line. It touches no service and no firewall rule, so run it before you enable a jail, or when bans never fire. The output below comes from a 12-line sample log written for this page (all addresses are 203.0.113.x). For a real log, pass /var/log/auth.log as is.
[1] Part of the sample. A sudo line is mixed in among the sshd lines.
2026-10-19T09:14:02.113456+09:00 server1 sshd[2101]: Failed password for invalid user admin from 203.0.113.7 port 51022 ssh22026-10-19T09:15:11.004412+09:00 server1 sshd[2110]: Invalid user test from 203.0.113.8 port 401122026-10-19T09:17:30.118004+09:00 server1 sshd[2131]: Unable to negotiate with 203.0.113.10 port 39880: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 [preauth]2026-10-19T09:18:01.900311+09:00 server1 sshd[2140]: Did not receive identification string from 203.0.113.11 port 600002026-10-19T09:19:00.010000+09:00 server1 sudo: alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/apt update[2] Pass the log file, then the filter. A bare name such as sshd reads /etc/fail2ban/filter.d/sshd.conf.
$ fail2ban-regex auth.log sshdRead the three numbers in the summary like this:
* matched — lines the filter counts as failures. In the sample: 4 Failed password, 1 Invalid user, 1 maximum authentication attempts exceeded. * ignored — lines not counted as failures. In the sample: Accepted publickey, Failed publickey, Connection closed by invalid user … [preauth]. sshd.conf tags these with <F-NOFAIL>, and ignoreregex is empty. * missed — lines no regex caught.
Under Failregex: each regex carries its hit count, like [5]. A regex with 0 hits is not listed.
[3] Missed lines follow the default output as Missed line(s):.
|- Missed line(s):| 2026-10-19T09:17:30.118004+09:00 server1 sshd[2131]: Unable to negotiate with 203.0.113.10 port 39880: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 [preauth]| 2026-10-19T09:18:01.900311+09:00 server1 sshd[2140]: Did not receive identification string from 203.0.113.11 port 60000| 2026-10-19T09:19:00.010000+09:00 server1 sudo: alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/apt update`-With many missed lines the list is hidden. With 19 unrelated lines everything printed; from 20 lines on, this message replaced the list:
Missed line(s): too many to print. Use --print-all-missed to print all 20 lines$ fail2ban-regex auth.log sshd --print-all-missed--print-all-matched and --print-all-ignored exist too, and --print-no-missed and --print-no-ignored switch the lists off.
[4] The sudo line has nothing to do with sshd, so missing it is correct. The other two lines are caught when you change mode. In sshd.conf the values are normal (default), ddos, extra and aggressive; set one in brackets after the filter name.
$ fail2ban-regex auth.log 'sshd[mode=aggressive]'Results on the same sample:
| mode | ignored | matched | missed | Changes from normal |
|---|---|---|---|---|
| normal | 3 | 6 | 3 | — |
| ddos | 2 | 8 | 2 | Did not receive identification string and Connection closed … [preauth] become matched |
| extra | 2 | 7 | 3 | Unable to negotiate … becomes matched; Connection closed … [preauth] moves from ignored to missed |
| aggressive | 2 | 9 | 1 | all three become matched; the one left is the sudo line |
The mdre-… entries in sshd.conf define which mode catches which line. Treat the result as input for choosing the jail's mode.
[5] Failed publickey works the same way. By default (publickey = nofail) it is ignored; with publickey=any it becomes matched.
$ fail2ban-regex auth.log 'sshd[publickey=any]'Lines: 12 lines, 2 ignored, 7 matched, 3 missed[6] To test a single line, pass the line itself as the log and a regex string as the filter. The regex is matched against what is left after the date is removed, so a leading ^ misses.
$ L='Oct 19 09:20:01 server1 sshd[2200]: Failed password for bob from 203.0.113.30 port 50001 ssh2'$ fail2ban-regex "$L" '^Failed password for .* from <HOST>'Lines: 1 lines, 0 ignored, 0 matched, 1 missedDrop the ^, or start with ^.*Failed password …, and you get 1 matched.
[7] To see only the addresses counted as failures, add -o ip. Instead of the summary, each matched line prints its address.
$ fail2ban-regex auth.log sshd -o ip203.0.113.7203.0.113.7203.0.113.7203.0.113.8203.0.113.9203.0.113.7The output has no maxretry verdict. Count the hits per address yourself and compare them with the jail settings.
Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.