為防止伺服器遭受ssh暴力破解,将嘗試ssh暴力破解本機超過10次的IP封掉,禁止其登陸本機!
#!/bin/bash
cat /var/log/secure |awk '/Failed/{print $(NF-10)}'| sort |uniq -c||awk '{print $2"="$1;}' > /home/test.list
for i in `cat /home/test.list`
do
IP=`echo $i |awk -F "=" '{print $1}'`
n=`echo $i |awk -F "=" '{print $2}'`
if [ ${n} -gt 10 ]; then
a=`grep $IP /etc/hosts.deny`
if [ -z $a ] ;then
echo "sshd:$IP:deny" >>/etc/hosts.deny
fi
fi
done
本文轉自super李導51CTO部落格,原文連結:http://blog.51cto.com/superleedo/1892200 ,如需轉載請自行聯系原作者