Think before you speak, read before you think.

ssh登录自动发邮件提醒

大前提:

因涉及到发邮件,debian下需安装exim4并可对外发邮件,centos则需安装mailx,sendmail。

方案1,对所有用户生效,创建文件

vim /etc/ssh/sshrc

加入以下内容

#!/bin/bash
[email protected]
mail -s "notification:user $USER login from ${SSH_CLIENT%% *}" $yourmail <<EOT
 the ip information : http://www.123cha.com/ip/?q=${SSH_CLIENT%% *}
 login date: `date +%Y/%m/%d" "%H:%M:%S`
 if this is not you , please contact xxx for help.
EOT

方案2,不影响他人,只针对自己的账户

vim ~/.bashrc

添加

echo 'ALERT Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" [email protected]

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *