To harden a new Linux VPS for a website, light API, or automation, set up and test key-based SSH first, review firewall rules before enabling them, then configure updates, isolate services, and plan off-site recovery.

Keep the first SSH session open until a second, key-based login works. Treat that as your handoff, not an optional extra.

1. Establish key-based SSH access

Start from a working administrator session and keep it open while you make access changes. Linformatique.org recommends this sequence:

  1. Generate an Ed25519 key pair and install its public key on the VPS.
  2. Create a dedicated administrator account with sudo privileges. Linformatique.org’s example names the account deploy.
  3. Open a second SSH session using the new key and confirm you can log in and administer the server. Keep the original session open during this test.
  4. After the new login works, disable root login and password authentication over SSH.

That order gives you a working route back in while you test the replacement. The example is a recommendation, not a distribution-specific command sequence.

2. Review UFW rules before enabling the firewall

On Ubuntu, UFW is the default firewall configuration tool and starts disabled. Allowing the services your VPS needs and enabling the firewall are separate actions. Ubuntu’s firewall documentation explains how to preview rules and inspect the active policy.

Before applying a proposed rule, run ufw --dry-run to preview its effect. Use ufw status or ufw status verbose to review the active rules. Allow inbound traffic only for services the deployment actually uses: SSH for administration, and TCP ports 80 and 443 when the server handles public web traffic.

If your administrative connection comes from a stable, known address, Ubuntu also documents restricting SSH access to a specific host or subnet. A restriction is useful only if you can reliably connect from the permitted network. Keep the existing SSH session open while changing access rules, and confirm the new policy still permits your second session.

3. Check what automatic updates cover

Ubuntu’s unattended-upgrades package normally runs daily and installs updates from configured repository origins. In Ubuntu’s default example, security origins are included while the -updates origin is commented out; additional repositories must be allowed explicitly. Ubuntu’s automatic-updates documentation also notes that updated packages may require service restarts. A reboot can be configured when an update requires one; automatic reboot is disabled by default in the documented configuration.

So, automatic installation is not the whole maintenance plan. Review which origins are enabled, and account for service restarts or a required reboot when planning updates.

4. Check container exposure as well as host rules

For a VPS running Docker, include published container services in your exposure review. A Docker for Linux issue report published June 5, 2019 described one setup in which a published port remained reachable externally despite a UFW deny rule. That report concerns the reporter’s configuration; it is a reason to check the actual network exposure of your deployment rather than rely on the host rule alone.

5. Limit application privileges and prepare recovery

Watch Tony Teaches Tech’s Fail2ban walkthrough: Ubuntu installation, SSH configuration, and a failed-login test

Linformatique.org recommends running each application under a separate, unprivileged system account. That keeps an application’s account distinct from the administrator account used to manage the VPS. The same publisher recommends daily off-site backups and a full restore test at least once per quarter.

For initial sizing, Linformatique.org suggests 2 vCPU and 4 GB of RAM for a cached editorial WordPress site or light API, and 8 or 16 GB of RAM for multiple containers or automation tools. These are its workload-specific recommendations.

Fail2ban can monitor logs for authentication failures and add firewall rules to block offending IP addresses. Tony Teaches Tech’s 2021 Ubuntu walkthrough demonstrates configuring it for SSH, including local configuration files and a test with repeated failed logins.