Here is how to do it
- Append the following to /etc/pam.d/sshd
session optional pam_exec.so seteuid /etc/ssh/login-notify.sh
- Create a new file /etc/ssh/login-notify.sh and add execution permission to the file
$ sudo touch /etc/ssh/login-notify.sh $ sudo chmod +x /etc/ssh/login-notify.sh
- Add the following to /etc/ssh/login-notify.sh
#!/bin/sh if [ "$PAM_TYPE" != "close_session" ]; then host="`hostname`" message="SSH Login: $PAM_USER from $PAM_RHOST on $host" DISPLAY=:0 /usr/games/xcowsay "$message"& fi
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 https://github.com/haude/xcowsay-utils
- 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