运维部落

首页 > Linux, 解决方案 > 设置ssh登陆邮件提醒

设置ssh登陆邮件提醒

2015年7月5日

Centos
wget ftp://ftp.freebsd.org/pub/FreeBSD/ports/distfiles/mailx-12.4.tar.bz2
tar jxvf mailx-12.4.tar.bz2
cd mailx-12.4
make
make install UCBINSTALL=/usr/bin/install
Ubuntu
sudo apt-get install heirloom-mailx -y
配置mailx
cp /etc/nail.rc /etc/nail.rc.bak
cat > /etc/nail.rc< set from=发送邮箱地址
set smtp=smtp服务器地址
set smtp-auth-user=发送邮箱登陆账号
set smtp-auth-password=发送邮箱登陆密码
set smtp-auth=login
EOF
配置SSH
cp /etc/ssh/sshrc /etc/ssh/sshrc.bak
cat > /etc/ssh/sshrc< #!/bin/bash
ip=\${SSH_CLIENT%% *}
if [ \`last -2 | grep \$ip -c\` = '1' ]; then
echo \$USER@\`hostname\` login from \$ip | mailx -v -s “SSH alert” 接收邮箱地址
EOF
chmod +x /etc/ssh/sshrc

» vps12.com:http://www.vps12.com
» 转载请注明来源:运维部落 » 《设置ssh登陆邮件提醒》
本文的评论功能被关闭了.