How to Enable SSH Login Notification on Linux CentOS server?

How to Enable SSH Login Notification on Linux CentOS server?

Is your Linux server is used by multiple people on same time? If yes, then add an SSH login notification on your server so you come to know whenever and whom login.

It will send you an email when someone login to your account. But for this its must that your server will be able to send an email by using a mail command. To do these use this tutorial code.

Replace your email id in this code, where you want to receive the notification mail


CentOS:

Open the file ~/.bash_profile in any text editor.
Apply the following code:

IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
HOSTNAME=$(hostname)
NOW=$(date +"%e %b %Y, %a %r")
echo 'Someone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | mail -s 'SSH Login Notification' YOUR_EMAIL_ADDRESS
Ubuntu/Debian:

Open the file ~/.bashrc in a text editor.
Apply the following code:

IP="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
HOSTNAME=$(hostname)
NOW=$(date +"%e %b %Y, %a %r")
echo 'Someone from '$IP' logged into '$HOSTNAME' on '$NOW'.' | mail -s 'SSH Login Notification' YOUR_EMAIL_ADDRESS
Author
bhawanisingh
Views
3,976
First release
Last update
Rating
0.00 star(s) 0 ratings
Top