Created
December 7, 2017 22:07
-
-
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
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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ein Kommentar zu obigem: Sobald DNS kaputt ist auf Deinem Host - und daher $Diensteanbieter nicht mehr resolved - kann sich niemand mehr einloggen…