How to set up an email alert when a ssh login is successful


How to set up an email alert when a ssh login is successful


If your like  to know who is logging into your linux servers, hopefully this blog entry will help you. So the scenerio goes someone has logged into your server through means not legal or ethical at some where and wants to do who knows what. It would be great to get a email notification to your phone via Email and wake up to take care of business.


Demonstrative Purpose I used Centos
Distributor ID: CentOS
Description:    CentOS release 6.7 (Final)
Release:        6.7
Codename:       Final


 The script below should help:

 Paste the below script in the .bash_profile at the end of the line

[root@techreno.blogspot.com ~]# vi .bash_profile



if [ -n "$SSH_CLIENT" ]; then
TEXT="$(date): ssh login to ${USER}@$(hostname)"
TEXT="$TEXT from $(echo $SSH_CLIENT|awk '{print $1}')"
echo $TEXT|mail -s "ALERT: Host Techreno.blogspot.com Accessed" Name@yourcompany.com
fi

Replace Name@yourcompany.com with the email address that you want to receive login notifications.


techreno.blogspot.com
.bash_profile



Result/Output

techreno.blogspot.com
 SSH Login Notification

 

I hope you  this information is useful for you. Please forgive any typos or incomplete sentences.

 

 

إرسال تعليق (0)
أحدث أقدم