Last active
January 23, 2022 02:34
-
-
Save alessandrocuda/88b83a83000a04e1e01df68731d33a76 to your computer and use it in GitHub Desktop.
Shell Script that sends alerts at login with sendmail and PAM https://medium.com/@alessandrocuda/ssh-login-alerts-with-sendmail-and-pam-3ef53aca1381
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Your Email Information: Recipient (To:), Subject and Body | |
RECIPIENT="yourAddr@email.com" | |
SUBJECT="Email from your Server: SSH Alert" | |
BODY=" | |
A SSH login was successful, so here are some information for security: | |
User: $PAM_USER | |
User IP Host: $PAM_RHOST | |
Service: $PAM_SERVICE | |
TTY: $PAM_TTY | |
Date: `date` | |
Server: `uname -a` | |
" | |
if [ ${PAM_TYPE} = "open_session" ]; then | |
echo "Subject:${SUBJECT} ${BODY}" | /usr/sbin/sendmail ${RECIPIENT} | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks
In order to make it work on my debian 9 i just edited few things: