Sshrc: Difference between revisions

From Coolscript
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:
  Target Hostname: $Hostname
  Target Hostname: $Hostname
  User: $USER
  User: $USER
  " | mail -s "SSH Login Alert From: $ip" mail.server.com
  " | mail -s "SSH Login Alert From: $ip" user@domain.com

Revision as of 18:34, 28 October 2021

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