Created
September 4, 2023 21:07
-
-
Save SpaceNerden/8cfee470217b0c0be3f4ba230286e9b2 to your computer and use it in GitHub Desktop.
SSH login notification with Gotify
This file contains hidden or 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/bash | |
# Append this command to /etc/pam.d/sshd: | |
# session optional pam_exec.so <path to script> | |
# Remember to chown +x! | |
exec &> /dev/null #Hide output | |
Gotify_URL='https://gotify.example.com' | |
Gotify_Token='awawawawawawawawawawawawa' | |
if [[ "$PAM_TYPE" != "open_session" ]]; then | |
exit 0 | |
fi | |
# Change the timezone if you need to | |
read -r -d '' CONTENT <<-EOF || true | |
Time UTC: $(date --utc "+%F %T") | |
Time Amsterdam: $(TZ=Europe/Amsterdam date '+%F %T') | |
IP Address: "$PAM_RHOST" | |
TTY: "$PAM_TTY" | |
EOF | |
/usr/bin/curl -X POST -s \ | |
-F "title=SSH - User ${PAM_USER} logged in" \ | |
-F "message=${CONTENT}" \ | |
-F "priority=1" \ | |
"${Gotify_URL}/message?token=${Gotify_Token}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment