I'm trying to let my server send me automatically an email on ssh-login.
What I've done:
login-notify.shfile (user root, group root, chmod 755) and placed it inside
#!/bin/sh if [ "$PAM_TYPE" != "close_session" ]; then # assembling my variable $TEXT ... echo $TEXT | mail -r "root@.... " - s "Subject line" root
echo "session required pam_exec.so seteuid /etc/ssh/login-notify.sh" | sudo tee -a /etc/pam.d/sshd
restarted sshd server and even rebooted the machine
Manually fired up
/etc/ssh/login-notify.sh-> mail successful sent
Logged in through ssh -> no mail has been sent
Addition steps / Information
for sending emails from command line I use ssmtp and a gmail-account
instead of sending a mail I've tried to append a string to a file and see if it works (echo "ssh login > /home/user/ssh-test) -> no luck...
server only accepts public/key authentication for ssh-logins
/var/log/syslogprovides no useful information:
Dec 27 14:20:51 srv1 fwknopd: Removed rule 1 from FWKNOP_INPUT with expire time of 1419686451 Dec 27 14:41:48 srv1 fwknopd: (stanza #1) SPA Packet from IP: xxx.xxx.xxx.xxx received with Access source match Dec 27 14:41:48 srv1 fwknopd: [xxx.xxx.xxx.xxx] (stanza #1) Incoming SPA data signed by 'XXXXXX'. Dec 27 14:41:48 srv1 fwknopd: Added Rule to FWKNOP_INPUT for xxx.xxx.xxx.xxx, tcp/xxx expires at 1419687738
After this line I logged in through ssh... no additional text was written to