SSH Login notification using Telegram bot

Using Telepot and pam.d we can set a simple script that notifies any successful login on our Linux box thru Telegram.

Bot setup

BotFather is the Telegram Bot to create Bots. Call it and create a new bot using /newbot. Grab the token. We will use it in a while

Notification script

I wrote it on Python, you may want to set your chat_id and your Telegram Bot ID.

Create a folder at /etc/pam.scripts

sudo mkdir /etc/pam.scripts

And place the Python code inside

sudo cp /etc/pam.scripts/

And grant execution permissions

sudo chmod +x /etc/pam.scripts/

Pam.d configuration

Edit sshd pam.d config file

sudo vim /etc/pam.d/sshd

And append the following line

session   required         /etc/pam.script/