linux防止暴力破解

简介:

暴露在外网的linux服务器,容易被扫描端口进行暴力破解密码,可以通过lastb查看短时间是否存在大量登录失败信息。

如果有那么机器存在被攻击的现象建议增强安全防护措施,1、密码强度增加;2、不使用默认端口;3、不允许root登录

4、多次登录失败限制ip访问ssh(主要说下这个实现)

vim  /opt/sesure_ssh.sh

#!/bin/bash
cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c | awk '{print $2"="$1;}'> /root/black.txt
DEFINE=10
for i in `cat  /root/black.txt`
do
    IP=`echo | awk '{split("'${i}'", array, "=");print array[1]}'`
    NUM=`echo | awk '{split("'${i}'", array, "=");print array[2]}'`
    if [[ $NUM -gt $DEFINE ]];then
     grep $IP /etc/hosts.deny > /dev/null
      if [ $? -gt 0 ];then
          echo "sshd:$IP:deny" >> /etc/hosts.deny
      fi
    fi
done

#增加执行权限

chmod +x  /opt/sesure_ssh.sh

#设置定时任务

crontab   -e 

*/5 * * * *    /opt/sesure_ssh.sh

 

posted @ 2022-04-10 23:40  记忆抹不去  阅读(568)  评论(0编辑  收藏  举报