Skip to content

Instantly share code, notes, and snippets.

@sprowell
Created December 12, 2019 03:57
Show Gist options
  • Save sprowell/c3cf9d04f52f764caa8b38d52071fea4 to your computer and use it in GitHub Desktop.
Save sprowell/c3cf9d04f52f764caa8b38d52071fea4 to your computer and use it in GitHub Desktop.
Script to notify alert@localhost on an SSH login or log out
#!/bin/bash
PATH=/bin:/usr/bin:/usr/sbin
SUBJ="Alert - Remote SSH access from ${PAM_USER}"
if [ -z "$PAM_TYPE" -o "$PAM_TYPE" == "open_session" ]
then
sendmail alert <<END
$(hostname) $(date): LOGIN by ${PAM_USER} from ${PAM_RHOST}
$(who)
END
else
sendmail alert <<END
$(hostname) $(date): LOG OUT by ${PAM_USER} from ${PAM_RHOST}
END
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment