linux beginner
Now Reading
How To Set Email Alerts for SSH Root Login In Linux
0

How To Set Email Alerts for SSH Root Login In Linux

To Set Email Alerts for SSH Root Login In Linux

While configuring Linux server, make sure that you should get a notification if any unauthorised login into root user. The server admin should get all email alerts from server. The procedure to set email alerts for SSH root login in Linux is explained.

Install the mailx package

Execute the following command to install mailx package.

[root@linuxhelp ~]# yum install mailx
Loaded plugins: aliases, changelog, fastestmirror, kabi, presto, refresh-packagekit, security, tmprepo,
              : verify, versionlock
Loading support for CentOS kernel ABI
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * epel: epel.mirror.net.in
.
.
.
Installing : mailx-12.4-8.el6_6.x86_64                                    1/1 
Verifying  : mailx-12.4-8.el6_6.x86_64                                    1/1 

Installed:
  mailx.x86_64 0:12.4-8.el6_6                                                   

Complete!

Go to /root directory and add the following statements in .bashrc file.

[root@linuxhelp ~]# vim .bashrc 
echo 'ALERT - Root Shell Access linuxhelp.com on:' `date` `who` | mail -s "Alert: Root Access"  corbyarun@gmail.com

snap1
Note : Enter your own server IP or Hostname and enter your valid mail-id.

Using ssh command, login to the configured server in terminal as root user.

root@linuxhelp:/home/user1# ssh root@192.168.5.83
root@192.168.5.83's password: 
Last login: Tue Jun 21 15:54:47 2016 from 192.168.5.137

A mail alert is sent to the respective mail-id, after the successful login.

snap2

snap3
To receive mail alert for multiple mail id’s, add the following lines in the .bashrc file.

[root@linuxhelp ~]# vim .bashrc
echo 'ALERT - Root Shell Access linuxhelp.com on:' `date` `who` | mail -s "Alert: Root Access"  corbyarun@gmail.com, arunkumarece@gmail.com

snap4

Again login to the server through ssh command.

root@linuxhelp:/home/user1# ssh root@192.168.5.83
root@192.168.5.83's password: 
Last login: Tue Jun 21 15:56:47 2016 from 192.168.5.137

Open the mail and check the alert
snap5

snap6

snap7

snap8
Note: Sometimes the mail will be stored in Spam.

Create alert for User login

Login as normal user. Go to user’s home directory and open the .bashrc file.

[root@linuxhelp ~]# cd /home/user1/
[root@linuxhelp user1]# vim .bashrc

snap9
Once the configuration is done, logout that user and again login to check the mail alert.

snap10
snap11

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.

For more help topics browse our website www.linuxhelp.com

Be the first to comment, we value your suggestions. For further queries please comment below.

Leave a Response