我正在尝试向我和用户发送电子邮件,有人试图登录他们的 ssh 并失败 - IP 被禁止。但我不明白如何在我尝试发送的电子邮件中使用该变量。
Sendmail 设置正确,因为电子邮件发送没有问题。
这是我的 jail.local 配置
[sshd]
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
action = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
%(mta)s-whois-lines-ssh[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
这是我的 action.d/sendmail-whois-lines-ssh.conf
[INCLUDES]
before = sendmail-common.conf
helpers-common.conf
[Definition]
norestored = 1
actionban = ( printf %%b "Subject: [Fail2Ban] <name>: banned <ip> from <fq-hostname>
Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
From: <sendername> <<sender>>
To: <dest>, <F-USER>@mydomain.cz\n
Hi,\n
The IP <ip> has just been banned by Fail2Ban after
<failures> attempts against <name>.\n\n
Here is more information about <ip> :\n
`/usr/bin/whois <ip> || echo missing whois program`\n\n
Lines containing failures of <ip>\n";
%(_grep_logs)s;
printf %%b "\n
Regards,\n
Fail2Ban" ) | /usr/sbin/sendmail -f <sender>.mydomain.cz <dest> <F-USER>@mydomain.cz
[Init]
name = default
logpath = /dev/null
发送给我的电子邮件很好,因为从配置中正确获取,但 <F-USER> 没有价值,因此它被发送到@mydomain.cz
我怎样才能获得价值,以便能够将电子邮件发送给用户?
编辑 在 SSH 上受到打击的正则表达式是这个:
^pam_unix\(sshd:auth\):\s+authentication failure;\s*logname=\S*\s*uid=\d*\s*euid=\d*\s*tty=\S*\s*ruser=<F-USER>\S*</F-USER>\s*rhost=<HOST>\s.*%(__suff)s$