ssh-login-alert
Persiapan
buat file bernama login_notify.sh di /etc/ssh/
sudo touch /etc/ssh/login_notify.sh
nano /etc/ssh/login_notify.sh
!img
#!/usr/bin/env bash
# Content of /etc/ssh/login_notify.sh
TELEGRAM_TOKEN="987654321:ABCDEFGHIJKLMNopqrstUVWXYZ123456789"
CHAT_ID=""
if [ ${PAM_TYPE} = "open_session" ]; then
MESSAGE="$PAM_USER@$PAM_RHOST: knock knock via $PAM_SERVICE"
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" -d chat_id="$CHAT_ID" -d text="$MESSAGE" > /dev/null 2>&1
fi
lalu berikan izin exekusi dengan command
sudo chmod +x /etc/ssh/login_notify.sh
Konfigurasi
pada konfigurasi pam ssh di /etc/pam.d/sshd tambahkan
sudo nano /etc/pam.d/sshd
#Login Telegram Notification
session optional pam_exec.so /etc/ssh/login_notify.sh
final
masukan command pada terminal
PAM_TYPE="open_session" /etc/ssh/login_notify.sh