问题原文
原帖链接 · apoc · CC BY-SA 3.0
fail2ban doesn't recognize failed public key ssh logins and I assume that this can be solved by modifying the failregex of /etc/fail2ban/filter.d/sshd.config to match the following line:
<date> <time> <server-hostname> sshd[25917]: Connection closed by <client-ip> [preauth]
But I can't find a decent introduction on how to correctly modify said failregex. As I don't really know what variables like ^%(__prefix_line)s include it's hard to get a working regex.
I understand that the most recent version 0.9.1 includes the regex to matche the "Connection closed by [preauth]" line, but I'm using fai2ban from the Debian repository and the configuration of 0.9.1 is not compatible with the one I have.
已采纳解答
原帖链接 · sebix · CC BY-SA 3.0
This line does it:
^%(__prefix_line)sConnection closed by <HOST> \[preauth\]$
Tested with the following logstring:
Apr 29 12:30:12 sendai sshd[25917]: Connection closed by 127.0.0.1 [preauth]
Successfully tested with:
$ fail2ban-regex ~/ssh.log sshd.conf
Running tests
=============
Use regex file : sshd.conf
Use log file : /home/user/ssh.log
Results
=======
Failregex
|- Regular expressions:
[...]
| [12] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*Connection closed by <HOST> \[preauth\]$
|
`- Number of matches:
[...]
[12] 1 match(es)
Summary
=======
Addresses found:
[...]
[12]
127.0.0.1 (Wed Apr 29 12:30:12 2015)
[..]
Success, the total number of match is 1
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
