Linux 服务器安全加固基础
发表于 : 周日 6月 14, 2026 8:28 am
服务器暴露在公网,安全是第一要务。列出几个基本操作。
[b]1. SSH 安全[/b]
[code]# 禁止密码登录,只用密钥
vim /etc/ssh/sshd_config
# 修改:
PasswordAuthentication no
PermitRootLogin prohibit-password
Port 2222 # 换端口减少扫描
systemctl restart sshd[/code]
[b]2. 防火墙[/b]
[code]# 只开放必要端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload[/code]
[b]3. 自动更新[/b]
[code]dnf install dnf-automatic
systemctl enable --now dnf-automatic[/code]
[b]4. Fail2ban[/b]
[code]dnf install fail2ban
systemctl enable --now fail2ban[/code]
配置 /etc/fail2ban/jail.local:
[code][sshd]
enabled = true
port = 2222
maxretry = 3
bantime = 3600[/code]
这些做完,基本的安全保障就有了。
[b]1. SSH 安全[/b]
[code]# 禁止密码登录,只用密钥
vim /etc/ssh/sshd_config
# 修改:
PasswordAuthentication no
PermitRootLogin prohibit-password
Port 2222 # 换端口减少扫描
systemctl restart sshd[/code]
[b]2. 防火墙[/b]
[code]# 只开放必要端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload[/code]
[b]3. 自动更新[/b]
[code]dnf install dnf-automatic
systemctl enable --now dnf-automatic[/code]
[b]4. Fail2ban[/b]
[code]dnf install fail2ban
systemctl enable --now fail2ban[/code]
配置 /etc/fail2ban/jail.local:
[code][sshd]
enabled = true
port = 2222
maxretry = 3
bantime = 3600[/code]
这些做完,基本的安全保障就有了。