SHARE
TWEET

Send an email on every ssh login with mail command

TringaliLuca Apr 12th, 2017 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. if [ "$PAM_TYPE" != "open_session" ]
  3. then
  4.   exit 0
  5. else
  6.   {
  7.     echo "User: $PAM_USER"
  8.     echo "Remote Host: $PAM_RHOST"
  9.     echo "Service: $PAM_SERVICE"
  10.     echo "TTY: $PAM_TTY"
  11.     echo "Date: `date`"
  12.   } | mail -s "$PAM_SERVICE login on `hostname -s` for account $PAM_USER" root
  13. fi
  14. exit 0
  15.  
  16. #please add
  17. #session optional pam_exec.so /root/send-mail-on-ssh-login.sh
  18. #to /etc/pam.d/sshd
  19. #your email could probably get marked as spam
  20. #if your mail is not sent, you probably need to run sendmailconfig
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top