Last active
May 3, 2022 08:08
-
-
Save meinside/091376305f6577b142e1e55204f192c1 to your computer and use it in GitHub Desktop.
Notify with pushbullet message on successful ssh logins
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 | |
# | |
# notify-ssh-login.sh | |
# | |
# Notifies successful ssh logins through pushbullet | |
# | |
# NOTE: this script will be run as root, so don't forget to put related config files under /root/.config/ | |
# | |
# | |
# last update: 2019.06.05. | |
# | |
# by [email protected] | |
# How-to: | |
# | |
# 1. Open /etc/pam.d/sshd, | |
# $ sudo vi /etc/pam.d/sshd | |
# | |
# 2. and append following lines (edit path to yours): | |
# # for notifying successful logins | |
# session optional pam_exec.so seteuid /path/to/this/notify-ssh-login.sh | |
# | |
# binary paths | |
# | |
# go get -u github.com/meinside/ipstack-go/cmd/ip2loc | |
LOCATOR=/path/to/ip2loc | |
# go get -u github.com/meinside/pb-send | |
SENDER=/path/to/pb-send | |
# fetch location, | |
LOCATION=`$LOCATOR "$PAM_RHOST"` | |
MESSAGE="sshd: $PAM_USER has successfully logged into `hostname`, from $LOCATION" | |
# on login, | |
if [ $PAM_TYPE == "open_session" ]; then | |
$SENDER "$MESSAGE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment