SSH 安全脚本

#! /bin/bash
#chkconfig:27501
#decription:secure_ssh.sh autostart

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 9 ]];then
                if [[ $result = "" ]];then
                        echo "sshd: $IP:deny" >> /etc/hosts.deny
                fi
        fi
done

cp /dev/null /tmp/black

exit

已发布

分类

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注