Telegram SSH Notifier
This is a simple Telegram SSH notifier script written in Bash. It sends notifications to a specified Telegram chat whenever an SSH session is initiated on the server.
Copy the ssh-notifier directory to the /usr/local/ directory to make it accessible publicly.
cp -r ssh-notifier /usr/local/
Open the /etc/pam.d/sshd file and add the following line at the end. This line invokes the notifier script with relevant parameters.
session required pam_exec.so /usr/local/ssh-notifier/app.sh "$PAM_USER" "$PAM_RHOST"
Restart the SSH service to apply the changes.
service ssh restart
Prior to utilizing the notifier, ensure that you create a .env file containing the necessary variables:
TELEGRAM_BOT_TOKEN="YOUR_BOT_TOKEN"
TELEGRAM_CHAT_ID="YOUR_CHAT_ID"
Replace YOUR_BOT_TOKEN and YOUR_CHAT_ID with your actual Telegram bot token and chat ID.
Once configured, the notifier will send a Telegram message whenever a user logs into the server via SSH.
Ensure that the necessary permissions are set for the script and that it is executable. You can use the following command:
chmod +x /usr/local/ssh-notifier/app.sh
Feel free to customize the script further to suit your needs.