题目描述:
猜密码:远程连接,如果猜错密码超过五次,就拒绝访问
实现描述:
通过查看日志,找到相应ip地址的失败记录,累加次数超过五次的将这个ip地址丢到/etc/hosts.deny文件中,写法是:sshd:ip
#!/bin/bash
for ip in $(cat /var/log/secure |grep "Failed password" |awk ‘{print $11}‘|sort
-rn |uniq -c|awk ‘{print $2}‘)
do
num=$(cat /var/log/secure |grep $ip |grep "Failed password" |wc -l)
if (($num>=5))
then
echo "$ip has been refused access,failed password:$num"
if ! cat /etc/hosts.deny |grep $ip &>/dev/null
then
echo "sshd:$ip" >>/etc/hosts.deny
fi
fi
done
本文出自 “爱武装一辈子” 博客,请务必保留此出处http://menglinux.blog.51cto.com/8733806/1439182
原文地址:http://menglinux.blog.51cto.com/8733806/1439182