前言,网络安全越来越重要,如何保证网站安全至关重要,在使用 Linux 服务器时,如果未设置有效安全登录屏障,每日将会有数百甚至数万次的密码暴力尝试登录,本篇章将介绍两种 Linux 登录安全防护
一:毫无疑问,使用密钥登录,安全系数极高,之前已经写好的了一篇教程,参考下链接
Linux 服务器配置使用密钥登录教程_linux配置密钥登录-CSDN博客
二:使用 Fail2ban 来设置暴力登录的 IP 限制
安装: 参考 https://github.com/fail2ban/fail2ban/wiki/How-to-install-fail2ban-packages
- #Centos
- yum install fail2ban -y
-
-
- # Debian
- apt-get install fail2ban -y
-
fail2ban 的设定文件为
- /etc/fail2ban/jail.conf
-
-
-
- #官方文档建议在同一目录新建 jail.local ,fail2ban 会先读取 jail.conf 然后在读取 jail.local 文件
-
- #进入对应目录新建 jail.local
-
- cd /etc/fail2ban/
-
- touch jail.local
然后编辑 jail.local 文件 ,以下简易配置表示相同的 IP 在 10 分钟内输错两次密码会禁止 24 小时内登录
- [DEFAULT]
- bantime = 24h
- banaction = iptables-multiport
- maxretry = 2
- findtime = 10m
-
- [sshd]
- enabled = true
重启 fail2ban
- #在 Debian 上:
-
- service fail2ban restart
-
- #在 CentOS 上:
-
- systemctl restart fail2ban
-
查看 fail2ban 运行状态
systemctl status fail2ban