How to Get Linux Server Sends Email Alert on Root Login

Another way to improve the security of your linux server is to enable server to automatically send a notification email to predefined email address everytime someone logs in as root to the host.

Procedures
1. Login to the server via SSH using as root ID.
2. Ensure that you’re at home directory of root. The open up the .bash_profile for editing using nano or vi by typing one of the following commands at command shell line:

[root@myserver ~]# nano .bash_profile
                   or
[root@myserver ~]# vi .bash_profile

3. Scroll down to the end of the file and add the following line:

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

Spread the love

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.