zh

VPS服务器安全加固:2025年完整实践指南

互联网上的服务器每天都面临数千次自动化扫描和攻击尝试。一台未经加固的VPS在上线后短短数分钟内就可能遭到暴力破解攻击。本指南提供系统化的安全加固步骤,帮助您将攻击面降至最低,保护服务器和数据安全。

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

一、强化SSH配置

SSH是管理VPS的主要入口,也是攻击者的首要目标。编辑SSH配置文件: nano /etc/ssh/sshd_config 关键配置项修改如下: - 将默认端口22改为非标准端口(如50022),减少自动扫描:Port 50022 - 禁止root直接登录:PermitRootLogin no - 禁止密码登录(仅允许密钥):PasswordAuthentication no - 限制登录尝试次数:MaxAuthTries 3 - 设置登录超时:LoginGraceTime 30 修改完成后重启SSH服务:systemctl restart sshd 重要提示:修改端口前务必先配置好防火墙开放新端口,并保持当前SSH会话不要断开,用新端口测试连接成功后再关闭旧会话。

二、安装和配置Fail2Ban

Fail2Ban会监控日志文件,自动封禁多次登录失败的IP地址,有效抵御暴力破解攻击。 安装Fail2Ban: apt install fail2ban -y (Ubuntu/Debian) 创建本地配置文件(不要直接编辑jail.conf,升级会覆盖): cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local nano /etc/fail2ban/jail.local 关键配置: [DEFAULT] bantime = 3600 # 封禁时长1小时 findtime = 600 # 10分钟内 maxretry = 5 # 最多5次失败 [sshd] enabled = true port = 50022 # 与SSH配置的端口一致 启动并设置开机自启: systemctl enable fail2ban && systemctl start fail2ban 查看封禁状态:fail2ban-client status sshd

三、配置自动安全更新

手动更新系统往往容易遗忘,启用自动安全更新可确保关键漏洞补丁及时应用。 Ubuntu/Debian系统安装unattended-upgrades: apt install unattended-upgrades -y dpkg-reconfigure -plow unattended-upgrades (按提示选择启用) 配置文件位于 /etc/apt/apt.conf.d/50unattended-upgrades,可自定义: - 是否自动重启:Unattended-Upgrade::Automatic-Reboot "false"; - 发送通知邮件:Unattended-Upgrade::Mail "您的邮箱@example.com"; 建议仅启用安全更新自动安装,大版本升级仍保持手动控制,避免生产环境中意外的兼容性问题。 完成以上配置后,您的VPS安全性将大幅提升。AnubizHost的离岸VPS提供DDoS防护,配合本指南的软件层加固,为您提供全方位的服务器安全保障。

Why Anubiz Host

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

Ready to get started?

Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.

Anubiz Chat AI

Online