First of all, you’ll need to have a Telegram account and create a Telegram bot
Put file ssh-telegram.sh to /usr/local/bin/
Remember to replace and with the real data of your own.
- With Debian/Ubuntu Edit file /etc/pam.d/common-session
session optional pam_exec.so type=open_session seteuid /usr/local/bin/ssh-telegram.sh
- With CentOS Edit the file /etc/pam.d/system-auth
session optional pam_exec.so type=open_session seteuid /usr/local/bin/ssh-telegram.sh