linux随记

1.linux服务器防骚扰,拉黑网络试图暴力破解ssh密码ip(可关闭ssh登录权限,启用秘钥登录)


#!/bin/bash
cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c |awk '{print $2"="$1}' > /root/likeme/script/black.txt

MAXCOUNT="8"

for i in `cat /root/likeme/script/black.txt`
do
    IP=`echo $i | awk -F= '{print $1}'`
    NUM=`echo $i | awk -F= '{print $2}'`

if [ $NUM -gt $MAXCOUNT ];then

   grep $IP /etc/hosts.deny > /dev/null
   if [ $? -gt 0 ];then
       echo "sshd:$IP" >> /etc/hosts.deny
   fi
fi
done

你可能感兴趣的:(linux,linux,服务器,运维)