Ubuntu – Get email notification for using ‘sudo’ by a specific user


I have a server set-up and I let somebody that I trust with a little bit of sudo access have it. However, I also want an email anytime that they use sudo.

I know that I can use Defaults mail_always to get an email anytime ANYONE tries to use sudo, but I have a cron-job for OwnCloud that runs every 30 minutes and requires a sudo -u www-data at the beginning of it. Obviously, I don't want an email every 30-minutes.

How can I always get an email just for 1 specific user?

Best Answer

After some experimentation, I found the answer. To set options such as mail_always or root_pw for specific users, you can add a line like this to your sudoers file after opening with visudo:

Defaults:USER_NAME mail_always

Just make sure that this line is inserted near the top, where the other Defaults options are. In addition, if you want to specify the recipient of the emails:

Defaults mailto="youremail@domain.tld"
Related Question