1.
大於10次登陸失敗就封掉IP,編寫shell腳本:secure_ssh.sh
#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /usr/local/bin/black.txt
for i in `cat /usr/local/bin/black.txt`
do
IP=`echo $i |awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
result=$(cat /etc/hosts.deny | grep $IP)
if [[ $NUM -gt 10 ]];then
if [[ $result = "" ]];then
echo "sshd: $IP" >> /etc/hosts.deny
fi
fi
done
2.
定時任務:10分鐘執行一次,crontab -e
*/10 * * * * bash /usr/local/bin/secure_ssh.sh