Hardening a Small Flexus Server: SSH, fail2ban, Swap and BBR

举报
yd_292978551 发表于 2026/10/31 10:01:52 2026/10/31
【摘要】 First steps I use on a small 2-core, 2 GB Ubuntu server: key-only SSH, fail2ban, a modest swap safety net, BBR tuning, and a closed firewall.

A 2-core, 2 GB cloud server is enough for a small site, but it leaves little room for mistakes. The hardening below is what I actually do first on a fresh Ubuntu server, before installing any application.

1. Start with SSH, not passwords

Disable password login and root login, and use a key only. In /etc/ssh/sshd_config I set PasswordAuthentication no and PermitRootLogin no, then restart sshd. I keep one working SSH session open while testing a second session, so a bad config cannot lock me out.

I also change nothing exotic: the goal is fewer ways in, not a clever setup I will forget. Key files stay on my own machine, never in the repository.

2. Let fail2ban do the boring blocking

Public servers get constant login attempts. fail2ban watches the SSH log and temporarily bans addresses that fail repeatedly. I enable the sshd jail, check it with fail2ban-client status sshd, and confirm the service is running after a reboot. It does not replace key-only login; it just stops the noise from filling the logs.

3. Give a small server breathing room with swap

With only 2 GB of RAM, a short spike can trigger the out-of-memory killer. A modest swap file is a safety net, not a performance plan. I create a swap file, set its permissions, enable it, and add it to /etc/fstab so it survives a reboot. I then check free -h and swapon --show to confirm it is present. If the server starts swapping heavily, that is a signal to fix the application or upgrade, not to keep enlarging swap.

4. Tune TCP with BBR, carefully

I enable BBR congestion control and the fq queue discipline through sysctl, then verify with sysctl net.ipv4.tcp_congestion_control. On a small server with a modest connection, this is a low-risk network tuning step, not a guarantee of speed. I measure before and after with a normal page load, rather than assuming an improvement.

5. Finish with updates and a firewall

I run unattended or regular apt updates, allow only SSH, HTTP and HTTPS through the firewall, and deny the rest by default. After each change I reboot once when I can, then verify SSH, the web service, fail2ban and swap again. A checklist that survives a reboot is worth more than a perfect first boot.

The lesson is simple: key-only SSH, automatic banning, a small swap safety net, sensible TCP tuning and a closed firewall make a small server much calmer to run.

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0)

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。