防止暴力破解服务器密码-shell脚本
crontab定时任务重启
*/10 * * * * /bin/bash /usr/local/src/bash/sshd_deny.sh > /dev/null 2>&1
#!/bin/bash
# -*- coding:UTF-8 -*-
#Author hanjinlei
#date: 2022-4-6
##########################################################
# #
# name: sshd_deny #
# description: 将多次ssh登录失败的IP放入hosts.deny黑名单 #
# #
##########################################################
lastb| awk '{count[$3]++}END{for(i in count){if(count[i]>5) print i}}' |\
while read ip;do
if grep -q "$ip" /etc/hosts.deny;then
continue
else
echo "sshd:$ip" >> /etc/hosts.deny
fi
done