PAM Login Notification Centos
Edit the file : /etc/pam.d/sshd
vi /etc/pam.d/sshd
Add this line to the above file :
session optional pam_exec.so /path/to/script.sh
Now Create the Script that will send the notification :
vi /path/to/script
Paste The Following content, and adjust the admin email address :
#!/bin/bash adminEmail="adminemail@yourdomain.com" [ "$PAM_TYPE" == "open_session" ] || exit 0 { echo "User: $PAM_USER" echo "Remote Host: $PAM_RHOST" echo "Service: $PAM_SERVICE" echo "TTY: $PAM_TTY" echo "Date: `date`" echo "Server: `hostname -s`" } | mail -s "`hostname -s` $PAM_SERVICE login: $PAM_USER" $adminEmail