How to show notification on ssh login

love team work, with ssh and x2x, and you want to feel secure then ...

Posted by @krazedkrish on February 26, 2016

Here is how to do it

  1. Append the following to /etc/pam.d/sshd
    session optional seteuid /etc/ssh/
  2. Create a new file /etc/ssh/ and add execution permission to the file
    $ sudo touch /etc/ssh/
    $ sudo chmod +x /etc/ssh/
  3. Add the following to /etc/ssh/
    if [ "$PAM_TYPE" != "close_session" ]; then
      message="SSH Login: $PAM_USER from $PAM_RHOST on $host"
      DISPLAY=:0 /usr/games/xcowsay "$message"&

    if your are and arch user replace this line

    DISPLAY=:0 /usr/games/xcowsay “$message”&

    with the following

    DISPLAY=:0 /usr/bin/xcowsay “$message”&

    if you want to used notify-send instead you can replace it with

    DISPLAY=:0 /usr/bin/notify-send “$message”& What I acutally use is

  4. If want a mail to be sent as a notification (probably because you want notification from the server), then replace the DISPLAY statement with
      echo "User: $PAM_USER"
      echo "Remote Host: $PAM_RHOST"
      echo "Service: $PAM_SERVICE"
      echo "TTY: $PAM_TTY"
      echo "Date: `date`"
      echo "Server: `uname -a`"
    } | mail -s "$PAM_SERVICE login on `hostname -s` for account $PAM_USER" root

    or something you like