Linux7 查看系统版本,禁用登陆错误超过5次的ip

cat /etc/centos-release

uname -a

 ***************************************************************************************************

#!/bin/bash

# 定义失败次数的阈值
threshold=5

# 提取登录失败的IP地址
failed_ips=$(awk '/Failed password/ {print $(NF-3)}' /var/log/secure | sort | uniq -c | awk '{if ($1 >= '$threshold') print $2}')

# 检查是否有失败的IP地址
if [ -z "$failed_ips" ]; then
echo "没有找到失败次数超过阈值的IP地址。"
exit 0
fi

# 将失败登录的IP地址添加到黑名单文件
echo "将以下IP地址添加到黑名单:"
for ip in $failed_ips; do
# 检查IP地址是否已存在于黑名单文件中
if ! grep -q "sshd:$ip" /etc/hosts.deny; then
echo "sshd:$ip" >> /etc/hosts.deny
echo "$ip"
fi
done

echo "黑名单已更新!"

***************************************************************************************************

查看用户登录历史记录

last -f /var/log/wtmp

lastlog -t 60 #60天内登录情况

posted @   云飞飏  阅读(101)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示