您的位置:首页 > 运维架构 > Shell

shell---登录失败的IP添加到/etc/hosts.deny

2016-01-10 23:22 357 查看
/etc/hosts.deny:俗称黑名单,控制远程访问设置。
#!/bin/bash           //程序开始
#File: hosts_deny.sh
#Date: 2016-01-10

grep 'Failed password' /var/log/secure | awk '{print $11}' | uniq -c | sort | \
//取出日志中登录失败的IP并统计排序

while read a b     //读取统计结果
do
grep -q $b /etc/hosts.deny     //测试IP是否存在,存在为0
if [ $? != 0 ] ; then
if [ $a -ge 5 ] ; then   //统计的次数大于等于5
echo "sshd: $b" >> /etc/hosts.deny    //添加IP到黑名单
fi
fi
done               //程序结束


本文出自 “经验来自痛苦” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: