How to send mail notification on user logn event
Regardless of user access, many times you have probably wanted to know when someone logs in into your server. And it is pretty easy to set up your Linux server to send mail notifications on user login events. Note that, if you have a system with many users who log in a few times a day, then you should expect a lot of mail traffic. To configure your Linux server to send mail on user logon event open your /root/.bashrc file and add the following line:
echo 'ALERT - Root Shell Access (`hostname -f`) on:' `date` `who` | mail -s "Alert: Root Access on `hostname -f` from `who | cut -d'(' -f2 | cut -d')\' -f1`" alias@domain.com
If you want to manually add the server name and not the FQDN, replace `hostname -f` with the desired server name.