来自: test@abc.com
致: root@abc.com,
日期: 11.04.2014 04:33主题: server1的安全信息
server1 : Apr 11 10:33:19 : test : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/bin/su -发布于 2018-12-07 10:17:01
我假设您使用rsyslog作为日志守护进程。将以下配置片段保存为/etc/rsyslog.d/60-sudo-mails.conf。
# Load Mail output module
module(load="ommail")
# Template for the "Subject:" line to dynamically set the affected hostname
template(
name = "mailSubject"
type = "string"
string = "SECURITY information for %hostname%"
)
# If messages go to facility "authpriv" and have severity "warning" (or worse)
# and the program's name is "sudo", then perform the given action:
if ( prifilt("authpriv.warning") and ($programname == "sudo") ) then {
action(
type = "ommail"
server = "your_mail_server_here, e.g. mail.abc.com"
port = "25"
mailfrom = "test@abc.com"
mailto = "root@abc.com"
body.enable = "on"
subject.template = "mailSubject"
)
}确保您配置了允许发送电子邮件而无需身份验证的邮件服务器。通常这将是本地网络中的邮件服务器,而不是GMail之类的,因为rsyslog's输出模块ommail目前无法配置为身份验证(用户名/密码)。
action.execOnlyOnceEveryInterval = "600"所以你每10分钟只收到一封电子邮件(其他的都被丢弃了)。这取决于你多久会收到这样的信息。
完成后,重新启动rsyslog:
sudo systemctl restart rsyslog.service通过发出禁止的sudo命令或运行
logger -p authpriv.warning -t sudo "This should be sent as an email"上面的配置会将日志消息“原样”放入邮件正文。如果您喜欢某种格式或不同的外观,那么您需要为电子邮件正文提供一个template
https://askubuntu.com/questions/1098647
复制相似问题