This script sends a Telegram notification whenever someone logs into your server via SSH.
- Bash
- curl
-
Create a Telegram bot: You can do this via BotFather.
-
Create a Telegram channel: This can be private or public, depending on your preference. This is where the alerts will be sent.
-
Get the bot updates: Create a URI in the following format:
https://api.telegram.org/bot*****:***-*****************/getUpdates
and invoke it.
-
Add your bot to the channel: This will allow the bot to send messages to the channel.
-
Get the channel ID: You can do this by visiting
https://api.telegram.org/bot*****:***-*****************/getUpdates
again. The channel ID will be listed there. -
Register at IPInfo: You can do this at ipinfo.io. This will give you an API token.
-
Update the script: Fill in the variables in the script with your Telegram bot token, channel ID, and IPInfo token.
-
Make the script executable: You can do this with the following command:
chmod +x ssh_notifier.sh
-
Test the script: Run the script and check that everything works correctly.
-
Update the SSHD PAM configuration: Add the following line to the end of
/etc/pam.d/sshd
:session optional pam_exec.so type=open_session seteuid /full/path/to/ssh_notifier.sh
This will run the script whenever someone logs into your server via SSH.
Now, try connecting to your server via SSH. You should receive a notification in your Telegram channel. Enjoy your new notification system!