Mail me when someone runs sudo

4

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

Defaults    mail_always
Defaults    mailto="email@domain.com"

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

bsmoo

Posted 2013-04-11T11:04:54.633

Reputation: 185

Answers

5

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="omgsudo@example.com"
Defaults:MailUsers mail_always
Defaults:NoMail    !mail_badpass

Gabe

Posted 2013-04-11T11:04:54.633

Reputation: 1 837

I can't seem to get this to work? Syntax error for both User_Alias commands – Sirens – 2017-06-30T19:20:58.217

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 – 2017-07-13T14:58:33.757

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 }

user2261750

Posted 2013-04-11T11:04:54.633

Reputation:

0

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

Defaults mailto="email@domain.com", mail_no_user

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

devnull

Posted 2013-04-11T11:04:54.633

Reputation: 2 987

This didn't work. There must be another option without filtering emails. – bsmoo – 2013-04-11T12:27:16.427

I didn't realize that mail_no_user is on by default. – None – 2013-04-11T12:32:48.183