SSH登录时向管理员发送邮件

首先去安装一个邮件服务

然后在~/.bash_profile文本中添加如下代码:

#!/bin/sh
echo "$USER@`hostname` login from ${SSH_CLIENT%% *} at $(date+%F' '%T)"|mail -s "Message for $USER login" test@163.com

source ~/.bash_profile

原文地址:https://www.cnblogs.com/cpw6/p/10190197.html