crontab
05 * * * * /root/bin/addDenyIp > /dev/null 2>&1 # 每5分钟检查一次登录日志(也就是说每个IP可以暴力登录5分钟)
/root/bin/addDenyIp.sh
#!/bin/bash # 把登录失败超过3次的IP添加到 hosts.deny cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /var/log/LoginFailedIP.list for i in `cat /var/log/LoginFailedIP.list` do IP=`echo $i |awk -F= '{print $1}'` NUM=`echo $i|awk -F= '{print $2}'` if [ ${#NUM} -gt 1 ]; then grep $IP /etc/hosts.deny > /dev/null if [ $? -gt 0 ];then echo "sshd:$IP:deny" >> /etc/hosts.deny fi fi done
– End –