SSH: Automatic notifications on login (Pushover)

The following snippet enables you to automatically trigger Pushover notifications for every SSH login on your server / NAS / desktop:

API_TOKEN=abcdefg1234hijklmno567890pqrstuv
API_USER=vutsrqp098765onmlkjih4321gfedcba
if [ -n "$SSH_CLIENT" ]; then
  USER_IP=`echo $SSH_CLIENT|awk '{print $1}'`
  TITLE="SSH: ${USER}@$(hostname -f) (${USER_IP})"
  TEXT="$(date)"

  curl -s \
  -F "token=$API_TOKEN" \
  -F "user=$API_USER" \
  -F "title=$TITLE" \
  -F "message=$TEXT" \
  -F "priority=0" \
  https://api.pushover.net/1/messages.json >/dev/null 2>&1
fi
Screenshot of Pushover notification
Just replace `API_TOKEN` and `API_USER` variables with your personal values. You can also customize the `priority` parameter to suite your needs. `1` would be high priority, whereas `2` requires you to acknowledge the respective notifications.

Put the above snippet into your server’s `/etc/ssh/sshrc` file to automatically inform you about every SSH login. Using `sshrc` is the „convenient“ solution and does not work, when the a user decides to override it e.g. with a `~/.ssh/rc` file. Refer to the following Stackoverflow discussion for further information and possible alternatives: https://askubuntu.com/questions/179889/how-do-i-set-up-an-email-alert-when-a-ssh-login-is-successful