A simple script to check whenever a user log in or log out from your system.
Based on this script but fixed, using only PAM.
- A server (tested on ubuntu)
- A telegram account
- Create a telegram bot from the BotFather and start a chat with it.
The url of your newly created bot will look like http://t.me/your_bots_name
Copy the HTTP API: token generated by the BotFather.
- Use
@getmyid_bot
bot to get your user ID. Should be in the form
Your user ID: XXXXXXXXX
Current chat ID: XXXXXXXXX
- Edit the script as below
- Check your
/etc/ssh/sshd_config
:UsePAM yes
it's mandatory. git clone https://github.com/Matteounitn/telegram-ssh-login-notification.git
cd telegram-ssh-login-notification
and herenano script.sh
HERE you HAVE TO SET:
USERID="<YOUR-ID>"
KEY="<API-KEY-OF-YOUR-BOT>"
sudo nano /etc/pam.d/sshd
and add the following snippet at the end of the file
session optional pam_exec.so /path/to/your/cloned/repo/telegram-ssh-login-notification/script.sh
sudo chmod a+x /path/to/your/cloned/repo/telegram-ssh-login-notification/script.sh
- Not mandatory, but reccomended:
sudo service ssh restart
orsudo systemctl restart sshd
orsudo systemctl restart ssh
This guy, for the basic script
Alberto Xamin for sending me the link and helping me with the code.