5

I have added the below lines to /etc/sudoers.d/my_sudoers

Defaults    mail_always
Defaults    mailto="[email protected]"

I get an email every time sudo is run

How can i modify this so I only receive emails when particular people run sudo (Everybody except 2 users)

Thanks

3 Answers 3

7

This is straightforward; Defaults can apply to specific users (and other limitations), and user aliases can be constructed with negated matches. Something along these lines:

User_Alias NoMail = goodboy, goodgirl
User_Alias MailUsers = ALL, !NoMail

Defaults           mailto="[email protected]"
Defaults:MailUsers mail_always
Defaults:NoMail    !mail_badpass
2
  • I can't seem to get this to work? Syntax error for both User_Alias commands
    – Allison
    Jun 30, 2017 at 19:20
  • You'll have to provide more detail, specifically the exact line(s) you're trying to use along with the exact error message(s).
    – Gabe
    Jul 13, 2017 at 14:58
0

I'm not to sure on the syntax but wouldn't creating an if statement help SUDO if (name = NAME1, NAME2,) { do nothing } else { email }

0

Assuming that only the two users exist in the sudoers file, the following will achieve what you want:

Defaults mailto="[email protected]", mail_no_user

Otherwise, you'll probably need to resort to filtering your emails.

2
  • This didn't work. There must be another option without filtering emails.
    – bsmoo
    Apr 11, 2013 at 12:27
  • I didn't realize that mail_no_user is on by default.
    – devnull
    Apr 11, 2013 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .