Technology and troubleshooting.

Friday, January 29, 2016

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 scenario 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 alert automatically to each successful login attempts via SSH server alert through email 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

[ ~]# 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 Accessed"

Replace with the email address that you want to receive login notifications.

 SSH Login Notification


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





Post a Comment

Popular Posts