Skip to content

Instantly share code, notes, and snippets.

@scy

scy/login-notify

Created Dec 7, 2017
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@schwindp 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
You can’t perform that action at this time.