您的位置:首页 > 运维架构 > Shell

shell 防止暴力破解

2017-01-16 10:28 239 查看
为防止服务器遭受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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell 防止 暴力