停止通过电子邮件向我发送错误的 sudo 密码尝试

Win*_*nix 2 email security password 16.04

我有 cron 设置来每天早上备份并将其通过电子邮件发送到我的 Gmail 帐户,效果很好。一个令人讨厌的副作用是,每当我使用 sudo 输入错误的密码时,我也会收到一封烦人的电子邮件:

登陆错误

我用谷歌搜索了一下,但找不到如何关闭此电子邮件功能。

内容/etc/sudoers

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)

ste*_*ver 6

man sudoers

 mail_badpass      Send mail to the mailto user if the user running sudo
                   does not enter the correct password.  If the command
                   the user is attempting to run is not permitted by
                   sudoers and one of the mail_all_cmnds, mail_always,
                   mail_no_host, mail_no_perms or mail_no_user flags are
                   set, this flag will have no effect.  This flag is off
                   by default.
Run Code Online (Sandbox Code Playgroud)

该标志默认情况下处于关闭状态 - 但由 Ubuntu 的默认 /etc/sudoers 文件启用,正如您所注意到的。

据推测,您已经开始接收这些邮件,因为sudoers默认值为mailto-root并且您配置了 MTA 来传递 root 的邮件cron。如果您注释掉该Defaults mail_badpass行(使用sudo visudo),则消息应该停止。

  • 修改默认的“/etc/sudoers”不是一个好主意,因为软件包升级后更改可能会丢失。最好在“/etc/sudoers.d”中使用“Defaults !mail_badpass”创建一个文件。 (4认同)