Skip to content

Instantly share code, notes, and snippets.

@scy
Created December 7, 2017 22:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scy/7a4208fd669624ab7eab690e38d90871 to your computer and use it in GitHub Desktop.
Save scy/7a4208fd669624ab7eab690e38d90871 to your computer and use it in GitHub Desktop.
Only allow SSH logins after a push notification to your phone has been sent
#!/bin/sh
# Only allow SSH logins after a push notification to your phone has been sent.
# Also sends a notification after logging out.
# This uses the Pushover service (pushover.net).
# If Pushover cannot be reached, the login will be denied!
# Add something like this to /etc/pam.d/sshd:
# session required pam_exec.so /usr/local/bin/login-notify
# For Debian, a good place is after "@include common-account".
# Get these two from Pushover.
user=''
token=''
host="$(hostname)"
message="$(printf '[%s] %s %s for %s@%s from %s\n' "$(date)" "$PAM_SERVICE" "$PAM_TYPE" "$PAM_USER" "$host" "$PAM_RHOST")"
title="$(printf '%s %s for %s@%s' "$PAM_SERVICE" "$PAM_TYPE" "$PAM_USER" "$host")"
case "$PAM_TYPE" in
open_session)
sound='gamelan'
;;
close_session)
sound='falling'
;;
*)
sound='pushover'
;;
esac
result="$(curl --silent --output /dev/null --write-out '%{http_code}' -v \
--form-string "user=$user" \
--form-string "token=$token" \
--form-string "title=$title" \
--form-string "message=$message" \
--form-string "sound=$sound" \
https://api.pushover.net/1/messages.json 2>/dev/null)"
if [ "$result" != '200' -a "$PAM_TYPE" = 'open_session' ]; then
exit 1
else
exit 0
fi
@schwindp
Copy link

schwindp commented Dec 8, 2017

Ein Kommentar zu obigem: Sobald DNS kaputt ist auf Deinem Host - und daher $Diensteanbieter nicht mehr resolved - kann sich niemand mehr einloggen…

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