Linux 服务器安全配置

AlmaLinux 9  服务器安全

启用 EPEL 仓库安装 sshguard

sudo dnf install epel-release -y
sudo dnf update -y
sudo dnf install sshguard -y


sudo dnf config-manager --set-disabled epel*       //长期禁用 EPEL 并只使用官方仓库

sudo dnf config-manager --set-enabled epel*      //允许使用 EPEL 
dnf repolist all | grep epel   //查看源的命令

配置示例(/etc/sshguard.conf)

# 使用 firewalld 作为防火墙后端
BACKEND="/usr/libexec/sshguard/sshg-fw-firewalld"

# 永久黑名单文件(自动写入)
BLACKLIST_FILE=90:/var/lib/sshguard/blacklist

# 单次封禁时长(秒)——这里设得比较短,只是触发永久黑名单用
BLOCK_TIME=3600

# 检测时间窗口(秒),在这个时间内累计计数
DETECTION_TIME=600

# 攻击分数阈值(3 次失败登录大约触发)
THRESHOLD=30

LOGREADER="LANG=C /usr/bin/journalctl -afb -o cat -t sshd"   // 保险做法是去掉 -p info,直接全抓:



sudo systemctl restart sshguard


//查看是否成功
nft list ruleset    
nft list set inet firewalld sshguard4     //生效IP
journalctl -u sshguard -n 20
journalctl -t sshd -S -5m | grep "Failed password"
sudo systemctl status sshguard




发表回复