Linux Ubuntu shell script to send email on SSH login based on IP

Within:
etc/profile

Add:

connip=($SSH_CLIENT)
echo “${connip[0]}”

if [ ${connip[0]} == 12.34.56.78 ]; then
    echo “User logged in from internal IP Address:” ${connip[0]} | mailx -s “Login alert” [email protected]
else
    echo “User logged in from internal IP Address :” ${connip[0]} | mailx -s “Login alert – External IP” [email protected]
fi

Share your love
Kieron Howard
Kieron Howard
Articles: 53

Leave a Reply

Your email address will not be published. Required fields are marked *