Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: E-mail alert when a successful root login occurs  (Read 2935 times)

0 Members and 1 Guest are viewing this topic.

Haripriya H

  • Guest
E-mail alert when a successful root login occurs
« on: January 12, 2014, 03:02:44 pm »
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.