Email Notification for Root Logins


Get notified instantly when someone logs into your server as root. Here is how to do it.

1st. Login as root in console, for ubuntu its sudo -i and for other distributions its simply su.
2nd. Edit your root bash file by typing: nano /root/.bashrc
3rd. Place this following code snippet at the bottom of the file (make sure to replace YourServerName and email with your own)

echo 'ALERT - Root Shell Access (YourServerName) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`"

This it. Now if your email server such as sendmail installed, you should receive root login notifications.

Leave A Reply

Please enter your comment!
Please enter your name here