看到有人提供了一个脚本,大于10次登陆失败就封掉IP。
脚本名称: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
定时任务:
crontab -e
*/10 * * * * bash /usr/local/bin/secure_ssh.sh
脚本来源:CSDN