Get Notified of SSH Logins

Here’s a quick tip of the day that I came across when I needed a way to get a notification on my mobile device when particular users log into a server. Turns out that the Linux PAM (Pluggable Authentication Modules) offers a convenient way to do this:

All that is required is an extra line in the following file:


# Add the following line to the file:
session optional seteuid /PATH/

Once the script is in place, the ‘’ script (don’t forget to make it executable) is called whenever a user logs in via ssh. And to only get notified for particular users, here’s my quick and dirty bash code for this:


# An array of the username for which to notify
"user-x" \
"user-y" \

if [ "$PAM_TYPE" != "close_session" ]; then

  for item in ${user[@]}; do

    if [ "$PAM_USER" = "${item}" ]; then




The array is of course only necessary if notifications should go out for more than one username. And for sending out a push notification, I recommend Gotify!