首先去安装一个邮件服务
然后在~/.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