码迷,mamicode.com
首页 > 其他好文 > 详细

限制ssh远程登陆

时间:2016-01-29 19:43:20      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

超过十次,就添加到hosts.deny里面去
#!/bin/bash
date=`date +%Y%m%d`
file="/var/log/secure"
max=10
if [[ -f $file ]]
then
        grep Failed $file | awk ‘{print $(NF-3)}‘ | sort -rn | uniq -c | awk ‘{print $2 "=" $1}‘>/shell/ip.txt
fi
for a in `cat /shell/ip.txt`
do
        if [[ `echo $a| awk -F"=" ‘{print $2}‘` -gt $max ]]
        then
                b=`echo $a | awk -F"=" ‘{print $1}‘`
                grep $b /etc/hosts.deny >/dev/null
                if [[ $? != 0 ]]
                then
                echo "sshd:$b" >> /etc/hosts.deny
                fi
        fi
done

限制ssh远程登陆

标签:

原文地址:http://www.cnblogs.com/GXLo/p/5169172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!