It is very useful to receive alert notifications via e-mail whenever a successful root login occurs. This will make sure that you are notified immediately (you can link the e-mail address to a mobile sms service) whenever someone logs in. This can be done very easily in several ways after logging into the CLI (Command Line Interface) as root:
[root@servername ~]#
Method 1:
Next, edit the .bashrc file (I prefer nano over vi for simplicity):
[root@servername ~]# nano .bashrc
Add the following line to the end of the .bashrc file:
echo -n 'ALERT - Root Shell Access (servername) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" email@address.com
Substitute “servername” and “email@address.com” for your servername and e-mail address, and save the file. This also works for other shell accounts on the system when you modify the shell user’s .bashrc file.
Method 2 :
Go to the .ssh directory:
[root@servername ~]# cd /root/.ssh
Create a file named “rc”:
[root@servername ~]# nano rc
Add the following line to the newly created rc file:
echo -n 'ALERT - Root Shell Access (servername) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" email@address.com
Substitute “servername” and “email@address.com” for your servername and e-mail address, and save the file.