This commit is contained in:
Max Isom 2016-09-16 14:04:16 -05:00 committed by GitHub
parent 69394a563b
commit 0720ffafb9
1 changed files with 13 additions and 10 deletions

View File

@ -1,18 +1,21 @@
#!/bin/bash
cat << 'EOF' > /etc/ssh/login-alert.sh
#!/bin/bash
source /etc/mailinabox.conf # load global vars source /etc/mailinabox.conf # load global vars
cat <<EOF >> /etc/ssh/login-alert.sh
#!/bin/sh
sender="bot@PRIMARY_HOSTNAME"
recepient="admin@$PRIMARY_HOSTNAME"
if [ "$PAM_TYPE" != "close_session" ]; then if [ "$PAM_TYPE" != "close_session" ]; then
subject="SSH Login: $PAM_USER from $PAM_RHOST" IP=$(echo $SSH_CONNECTION | cut -d ' ' -f 1)
# Message to send, e.g. the current environment variables. sendEmail -q -f "bot@$PRIMARY_HOSTNAME" -t "admin@$PRIMARY_HOSTNAME" -u "SSH Login: $PAM_USER from $PAM_RHOST" -m "If you don't recognize this login, your key or password may be compromised."
message="If you don't recognize this login, your key or password may be compromised."
echo "$message" | mailx -r "$sender" -s "$subject" "$recepient"
fi fi
EOF EOF
chmod +x /etc/ssh/login-alert.sh chmod +x /etc/ssh/login-alert.sh
echo 'session optional pam_exec.so seteuid /etc/ssh/login-alert.sh' >> /etc/pam.d/sshd if grep -Fq "login-alert" /etc/pam.d/sshd
then
:
else
echo 'session optional pam_exec.so seteuid /etc/ssh/login-alert.sh' >> /etc/pam.d/sshd
fi