mailinabox/setup/login-alerts.sh

19 lines
607 B
Bash
Raw Normal View History

2016-09-16 16:56:05 +00:00
source /etc/mailinabox.conf # load global vars
2016-09-16 16:39:40 +00:00
2016-09-16 16:56:05 +00:00
cat <<EOF >> /etc/ssh/login-alert.sh
2016-09-16 16:39:40 +00:00
#!/bin/sh
2016-09-16 16:56:05 +00:00
sender="bot@PRIMARY_HOSTNAME"
recepient="admin@$PRIMARY_HOSTNAME"
2016-09-16 16:39:40 +00:00
if [ "$PAM_TYPE" != "close_session" ]; then
2016-09-16 16:56:05 +00:00
subject="SSH Login: $PAM_USER from $PAM_RHOST"
2016-09-16 16:39:40 +00:00
# Message to send, e.g. the current environment variables.
message="If you don't recognize this login, your key or password may be compromised."
echo "$message" | mailx -r "$sender" -s "$subject" "$recepient"
2016-09-16 16:56:05 +00:00
fi
EOF
2016-09-16 16:39:40 +00:00
chmod +x /etc/ssh/login-alert.sh
echo 'session optional pam_exec.so seteuid /etc/ssh/login-alert.sh' >> /etc/pam.d/sshd