Get Email Alert on Root Login Linux
To improve the security of the server, especially web server which exposes to the Internet and possible worldwide hackers, it’s best to enable server to automatically send a notification email to predefined email address every time someone logs in as root to the host.
You can configure the automatic email alert notification to a email address on each incident of root log on on the server.
- Login to the server via SSH using as root ID.
- Ensure that you’re at home directory of root. The open up the .bash_profile for editing using pico or vi by typing one of the following commands at command shell line:
- cd /root
- vi .bashrc
- Scroll to the end of the file then add the following:
echo ‘ALERT – Root Shell Access (YourserverName) on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d”(” -f2 | cut -d”)” -f1`”firstname.lastname@example.org
Replace gmail with the handle for your actual server
Replace email@example.com with your actual email address
- Save this file by pressing ESC key and type wq! and then press Enter.