- Open your app and search for @BotFather, or open this link: https://telegram.me/botfather.
- Type
/newbot
- Name your new bot (this is the contact name, like "Bot My server")
- Give it a unique Telegram name, ending with
bot
(like "my_server_bot") - Now, you should see a token: keep it safe!
- Search for @IDBot
- Start a new discussion with it and type
/getid
- Start a new discussion with your bot to enable it
- Update the
USERID
in the script
Create a new file /usr/local/bin/telegram-alert.sh
and copy the script.
Add a new line at the end of the file /etc/pam.d/sshd
:
session optional pam_exec.so type=open_session seteuid /usr/local/bin/telegram-alert.sh
Apply the correct rights:
chmod +x /usr/local/bin/telegram-alert.sh
# For SELinux
restorecon /usr/local/bin/telegram-alert.sh
ausearch -c "sshd" --raw | audit2allow -M my-sshd
semodule -X 300 -i my-sshd.pp
Now, on SSH connection and disconnection you will receive a new Telegram notification by your bot!
Maybe a comment like the next could be useful for others: