How to Get Instant Telegram Alerts on Every Successful SSH Login to Your Server
A simple setup using Linux's Pluggable Authentication Modules (PAM) can send real-time Telegram notifications whenever someone successfully logs into a server via SSH. The system hooks into PAM's pam_exec module, which triggers a shell script only after a successful login, then calls the Telegram Bot API via curl to deliver the alert. The script is designed to always exit with a success code and runs the network request in a detached subshell, ensuring the notification process never delays or blocks the actual login. Rate limiting per IP and username is built in to prevent notification spam from tools like VS Code Remote, which can open multiple SSH channels for a single session. The approach requires no third-party agents or complex configuration — just a Telegram bot token, a chat ID, and a few lines added to the PAM SSH config file.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in