Last active
August 7, 2017 10:37
-
-
Save fincham/1fbe160e10b3a866efdbe6c8cdcf8306 to your computer and use it in GitHub Desktop.
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/bash | |
# Send a Twilio SMS when a person logs in over SSH or uses sudo. Michael Fincham <michael@hotplate.co.nz> 2017-05-22 | |
# | |
# For a Debian host: | |
# - Install the packages for libpam-script and curl | |
# - Edit this script to set the configuration variables, and place it in /usr/share/libpam-script/pam_script_acct | |
# - Add this line to /etc/pam.d/common-account: | |
# account optional pam_script.so | |
from_number="+15555555555" | |
to_number="+15555555555" | |
account_sid="ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
auth_token="8f9c65c158d57c6bbb58102ac8b62361" | |
case ${PAM_SERVICE} in | |
sshd|sudo) | |
if [[ ${#PAM_RHOST} -gt 0 ]]; then | |
remote_host_string=" from ${PAM_RHOST}" | |
else | |
remote_host_string="" | |
fi | |
curl -X POST -F "Body=${PAM_USER} logged in to ${PAM_SERVICE} on $(hostname -f)${remote_host_string} at $(date)" \ | |
-F "From=${from_number}" \ | |
-F "To=${to_number}" \ | |
"https://api.twilio.com/2010-04-01/Accounts/${account_sid}/Messages" \ | |
-u "${account_sid}:${auth_token}" >/dev/null 2>&1 & | |
;; | |
*) | |
exit 0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks finchy love u lots xoxo