In this post I will guide you how to set the mail alert if somebody logins to the server as root.
Step1. Login to your server as root:
ssh root@debian-tutorials.com
root@debian-tutorials.com’s password:
root@deb:~#
Step2. Edit the .bashrc file as follows:
Open the file:
nano .bashrc
Add the following code to the end of the file:
echo ‘SECURITY ALERT – Someone has logged in as root on:’ `date` `who` | mail -s “Security Alert: Root login from `who | cut -d’(‘ -f2 | cut -d’)’ -f1`” contact[@]debian-tutorials.com
NOTE: Replace contact[@]debian-tutorials.com with your valid email address.
Step3. Now logout from the server and relogin. You will receive an email with the root login alert .
Enjoy.














