Notification texts go here Contact Us Buy Now!

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.

 

 

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.