Skip to content

Instantly share code, notes, and snippets.

@meinside
Last active May 3, 2022 08:08
Show Gist options
  • Save meinside/091376305f6577b142e1e55204f192c1 to your computer and use it in GitHub Desktop.
Save meinside/091376305f6577b142e1e55204f192c1 to your computer and use it in GitHub Desktop.
Notify with pushbullet message on successful ssh logins
#!/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