Telegram SSH Notifier
![image](https://private-user-images.githubusercontent.com/35873101/285546986-d7093063-d949-4568-9ed0-4dcee8c20b24.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0MTc3NjUsIm5iZiI6MTczOTQxNzQ2NSwicGF0aCI6Ii8zNTg3MzEwMS8yODU1NDY5ODYtZDcwOTMwNjMtZDk0OS00NTY4LTllZDAtNGRjZWU4YzIwYjI0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDAzMzEwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwM2E0MTUwNzVhOTI4YjQ2NWNhMGI0NjA0YWZlOTFhY2IwYzEwMTkxMTA0YjAyYmNlNTRlMDFiOTcwYTA3MjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.BietMuBfRrGeuZqne5kQ2H_Ghw9ivKKlstifYQsaaO0)
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.