Linux弱口令登录限制脚本
查看近期登陆日志:cat /var/log/secure计算近期失败的登陆次数:cat /var/log/secure|grep ‘Failed password for root‘|wc -l
流量检测
netstat -n -p|grep SYN_REC | wc -l
脚本。。。
#! /bin/bash
#禁止弱口令
cat /var/log/secure|awk ‘/Failed/{print $(NF-3)}‘|sort|uniq -c|awk ‘{print $2"="$1;}‘ > black.txt
#尝试登录的次数和ip
DEFINE="5"
#单个ip尝试登录最大值
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 #扔到hosts文件中
fi
fi
done`
相关推荐
linuxwcj 2020-10-21
彼岸随笔 2020-10-20
yutou0 2020-10-17
jarrygao 2020-11-02
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
momoku 2020-09-11
ruancw 2020-08-27
TuxedoLinux 2020-08-18
vvu 2020-08-16
downtown 2020-08-11
luvzhan 2020-07-28
maxelliot 2020-06-28
cuixingwudi 2020-06-25
linuxdashencom 2020-06-21
旭灿 2020-06-16
wenjieyatou 2020-06-14