#!/bin/bash
while true
do
badip=$(lastb -i -a | awk ‘/ssh:notty/ {print $NF}‘|sort|uniq -c|awk ‘($1>3) {print $2}‘)
for i in $badip
do
iptables -t filter -I INPUT -s $i -p tcp --dport 22 -j DROP
done
: > /var/log/btmp
sleep 10s
done
本文出自 “运维!解放!” 博客,谢绝转载!
shell脚本精华----在10秒内SSH登录失败次数超过3次就使用iptables/tcpwrappers拒绝,布布扣,bubuko.com