SSH login notification

From Emerald Mockingjay, 5 Months ago, written in Bash, viewed 98 times.
URL https://paste.monocul.us/view/60200ac1 Embed
Download Paste or View Raw
  1. #!/bin/sh
  2. # da mettere in /etc/profile.d
  3. telegrambot="redacted"
  4. telegramchatid="redacted"
  5.  
  6. url="https://api.telegram.org/bot"$telegrambot"/sendMessage"
  7.  
  8. date="$(date "+%F %T")"
  9.  
  10. if [ -n "$SSH_CLIENT" ] ; then
  11.         ip_address=$(echo $SSH_CLIENT | awk '{print $1}')
  12.  
  13.         reverse_dns=`dig -x $ip_address +short`
  14.  
  15.         if [ -z "$reverse_dns" ] ; then
  16.                 reverse_dns=$ip_address
  17.         fi
  18.  
  19.         message="New remote SSH connection : "$USER"@"$(hostname)" from ["$reverse_dns"](http://whatismyipaddress.com/ip/"$ip_address"#General-IP-Information)
  20. "$date
  21.  
  22.         curl -s -d "chat_id="$telegramchatid"&text=$message&parse_mode=markdown&disable_web_page_preview=1" $url > /dev/null 2>&1
  23. fi

Reply to "SSH login notification"

Here you can reply to the paste above