最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Centos下防止ssh暴力破解shell脚本
时间:2022-06-30 20:52:18 编辑:袖梨 来源:一聚教程网
脚本
#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black.txt #筛选出状态为Failed的ip和次数
cat /var/log/secure|awk '/Invalid user/{print $NF}'|sort|uniq -c|awk '{print $2"="$1;}' >> /root/black.txt #筛选出状态为Invalid user的ip和次数
DEFINE="20" #规定允许次数为20次
for i in `cat /root/black.txt`
do
IP=`echo $i |awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ];
then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ];
then
echo "sshd:$IP" >> /etc/hosts.deny
fi
fi
done
规定当登录失败或者非法用户的ip次数达到20次后就把ip加入到hosts.deny中。
因为secure日志文件是每周六就会自动存档,于是我们可以写个排程定制去跑这个脚本
每天凌晨1点运行
0 1 * * * /usr/local/bin/ssh_black.sh 2>&1 >>/dev/null
相关文章
- Switch版《超级马力欧银河》合集迎来不错的限时折扣 07-15
- 《Reanimal》试玩版现已上线 Switch 2 07-15
- 《神探杰克鼠》支线2玩法介绍 07-15
- 王者万象棋如何吃分 07-15
- 消考宝app如何注册 07-15
- 红色沙漠信念流浪者披风怎么获得 07-15