首页 > 代码库 > shell 防止暴力破解

shell 防止暴力破解

为防止服务器遭受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




本文出自 “实用Linux知识技能分享” 博客,请务必保留此出处http://superleedo.blog.51cto.com/12164670/1892200

shell 防止暴力破解