Receive a notification every time a SSH-authentication is successful.
First, install ssmtp.
Create the notify-script.
#!/bin/sh
# Change these two lines:
sender="[email protected]"
recepient="[email protected]"
if [ "$PAM_TYPE" != "close_session" ]; then
host="`hostname`"
subject="New SSH login on $host"
echo "Subject: $subject\n\nUser: $PAM_USER\nFrom: $PAM_RHOST" | sendmail -v $recepient
fi
Enable script by adding the following line to /etc/pam.d/sshd
.
session optional pam_exec.so seteuid /path/to/ssh-notify.sh
Restart ssh service.
$ sudo service ssh restart