Last active
May 24, 2026 07:26
-
-
Save kolbanidze/4d4f2b041d59febd96c74178592c7cd3 to your computer and use it in GitHub Desktop.
SSH login notification via Telegram bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| TELEGRAM_TOKEN="" | |
| CHAT_ID="" | |
| if [ "$PAM_TYPE" != "open_session" ]; then | |
| exit 0 | |
| fi | |
| HOSTNAME=$(cat /etc/hostname) | |
| DATE=$(date +"%Y-%m-%d %H:%M:%S") | |
| MESSAGE="⚠️ <b>Successful SSH login</b>%0A" | |
| MESSAGE+="<b>Hostname:</b> $HOSTNAME%0A" | |
| MESSAGE+="<b>User:</b> $PAM_USER%0A" | |
| MESSAGE+="<b>IP address:</b> $PAM_RHOST%0A" | |
| MESSAGE+="<b>Service:</b> $PAM_SERVICE%0A" | |
| MESSAGE+="<b>Time:</b> $DATE" | |
| cat << EOF | curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" -d @- > /dev/null 2>&1 & | |
| chat_id=$CHAT_ID&text=$MESSAGE&parse_mode=HTML | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment