Skip to content

Instantly share code, notes, and snippets.

@fincham
Last active August 7, 2017 10:37
Show Gist options
  • Save fincham/1fbe160e10b3a866efdbe6c8cdcf8306 to your computer and use it in GitHub Desktop.
Save fincham/1fbe160e10b3a866efdbe6c8cdcf8306 to your computer and use it in GitHub Desktop.
#!/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
@fincham
Copy link
Author

fincham commented May 22, 2017

Fixed the wacky indentation.

@skooch
Copy link

skooch commented May 22, 2017

Thanks finchy love u lots xoxo

@fincham
Copy link
Author

fincham commented Aug 7, 2017

NP :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment