不要再通过电子邮件向我发送错误的 sudo 密码尝试信息

不要再通过电子邮件向我发送错误的 sudo 密码尝试信息

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

登陆错误

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

内容/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

答案1

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.

该标志默认是关闭的 - 但正如您所注意到的,它由 Ubuntu 的默认 /etc/sudoers 文件启用。

假设您已经开始收到这些邮件,因为sudoers默认mailtoroot- 并且您配置了一个 MTA 来为 递送 root 的邮件cron。如果您注释掉该Defaults mail_badpass行(使用sudo visudo),邮件应该会停止。

相关内容