linux 每次登录发邮件通知
添加如下内容到 /etc/pam.d/sshd
1 |
session optional pam_exec.so seteuid /usr/local/bin/login-notify.sh |
通知脚本 /usr/local/bin/login-notify.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/sh # Change these two lines: sender="root@example.com" recepient="root" if [ "$PAM_TYPE" != "close_session" ]; then host="`hostname`" subject="SSH Login: $PAM_USER from $PAM_RHOST on $host" # Message to send, e.g. the current environment variables. message="`env`" echo "$message" | mailx -r "$sender" -s "$subject" "$recepient" fi |
添加可执行权限
# chmod 0700 /usr/local/bin/login-notify.sh
分类: 技术