当前位置: 代码迷 >> 综合 >> 限制ssh远程登陆
  详细解决方案

限制ssh远程登陆

热度:94   发布时间:2023-10-19 01:23:23.0

超过十次,就添加到hosts.deny里面去

 
#!/bin/bash
date=`date +%Y%m%d`
file="/var/log/secure"
max=10
if [[ -f $file ]]
thengrep 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`
doif [[ `echo $a| awk -F"=" '{print $2}'` -gt $max ]]thenb=`echo $a | awk -F"=" '{print $1}'`grep $b /etc/hosts.deny >/dev/nullif [[ $? != 0 ]]thenecho "sshd:$b" >> /etc/hosts.denyfifi
done
  相关解决方案