首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当有人试图使用"sudo“时,我如何创建电子邮件警报?

当有人试图使用"sudo“时,我如何创建电子邮件警报?
EN

Ask Ubuntu用户
提问于 2018-12-05 13:12:02
回答 1查看 630关注 0票数 0

来自: test@abc.com

致: root@abc.com,

日期: 11.04.2014 04:33主题: server1的安全信息

代码语言:javascript
复制
server1 : Apr 11 10:33:19 : test : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/bin/su -
EN

回答 1

Ask Ubuntu用户

发布于 2018-12-07 10:17:01

我假设您使用rsyslog作为日志守护进程。将以下配置片段保存为/etc/rsyslog.d/60-sudo-mails.conf

代码语言:javascript
复制
# 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目前无法配置为身份验证(用户名/密码)。

代码语言:javascript
复制
action.execOnlyOnceEveryInterval = "600"

所以你每10分钟只收到一封电子邮件(其他的都被丢弃了)。这取决于你多久会收到这样的信息。

完成后,重新启动rsyslog

代码语言:javascript
复制
sudo systemctl restart rsyslog.service

通过发出禁止的sudo命令或运行

代码语言:javascript
复制
logger -p authpriv.warning -t sudo "This should be sent as an email"

上面的配置会将日志消息“原样”放入邮件正文。如果您喜欢某种格式或不同的外观,那么您需要为电子邮件正文提供一个template

票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1098647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档