Sshrc

From Coolscript
Revision as of 18:31, 28 October 2021 by Admin (talk | contribs)
Jump to navigation Jump to search

E-Mail Alert on SSH Login Event

  • /etc/ssh/sshrc
#!/bin/bash
#email on ssh login
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
Hostname=`hostname`
NOW=$( date '+%F_%H:%M:%S' )
Country=`curl -s https://ipapi.co/$ip/country/` > /dev/null

echo  "
UTC Date/Time: $NOW
IP Address: $ip
Country: $Country
Target Hostname: $Hostname
User: $USER
" | mail -s "SSH Login Alert From: $ip" mail.server.com