首页 > 技术文章 > SSH登录时向管理员发送邮件

cpw6 2018-12-28 14:02 原文

首先去安装一个邮件服务

 

然后在~/.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

推荐阅读