This login notifier uses IP information to send silent telegram notifications if the login source seem to be trustable.
First, please read this awesome Medium tutorial on how to setup the Telegram bot.
In order to send Telegram messages, you have to copy and paste the telegram-send
file to /usr/bin/telegram-send
and run
chmod +x /usr/bin/telegram-send
in order to make the script executable. Make sure to replace the placeholders
with your custom values
After that, you can already send messages to your Telegram channel by typing telegram-send FALSE This is a Telegram test
.
This first argument specifies whether the message should be silent or not.
After setting up the Telegram script you may now create the notify script itself by copy and pasting the
login-notify.sh
file to /etc/pam_scripts/login-notify.sh
and run chmod +x /etc/pam_scripts/login-notify.sh
in order to make this script executable, too.
Make sure to replace the placeholders with your custom values
If not installed, you have to install the JSON parser jq
. When using a Debian/Ubuntu system, the package can be installed by running:
sudo apt install jq
Finally you have to set up the PAM part by adding the following line to your /etc/pam.d/sshd
file:
# Login Telegram Notification
session optional pam_exec.so /etc/pam_scripts/login-notify.sh
After you did that, you should be good to go and be notified when you login onto your Linux machine using ssh.
Base articles this tutorial is based on: