Send Email Alert on SSH Access

How to send an email alert on SSH access? Here we go

#nano ~/.bash_profile

and add this at the bottom of the page

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@domain.com

Please rate this article to help us improve our Knowledge Base.

0 0