Monday, December 5, 2011

ssh client login email alert


I just got it when searching via google, I forgot the link but thanks for this share.


The code below should be inserted at /etc/profile so that every time someone logon via ssh in your server, it will send an email alert, assuming that the server is capable of sending an email via command line which will not be tackled here.

################
if [ -n "$SSH_CLIENT" ]; then

   TEXT="$(date): ssh login by ${USER}@$(hostname -f)"

   TEXT="$TEXT from $(echo $SSH_CLIENT|awk '{print $1}')"

   echo $TEXT|mail -s "ssh login" linux.admin@mydomain.com

fi
#
###############