Secure an internet-facing server before anything else
Field: server security, remote access, self-hosting
For: SME owners who rent or are about to rent a server, and their IT person
Experience: the security foundation of my own servers, applied to every new machine
A server rented from a hosting provider can be reached from the whole internet from its very first minute. Bots sweep the internet constantly looking for machines to try, and attempt passwords relentlessly. The usual reflex is to install the useful application first and "secure it later". I do the opposite: I lock the server down before installing anything on it. Here is the approach, layer by layer, and what each layer spares you.
Background
An ERP, a password vault, file sharing or an AI assistant: many SMEs are bringing part of their IT back onto a server of their own, as I describe in the map of open source software for SMEs. It is a good decision, on one condition: the foundation must be solid. A poorly locked server does not put one application at risk, but every application it hosts, and your customers' data along with them.
The problem: a new server is an open door
A new server is not protected by default. In the setups I come across, the same weaknesses keep coming back:
- Administrator access by password: one guessed password, or one reused elsewhere and stolen, is enough for the server to change hands.
- Too many visible doors: every installed service opens one more access point from the internet, often without anyone having decided it.
- The firewall you think is active: it is in place, but a tool installed later publishes its own access points and goes around it.
- Admin pages open to the public: the login screen of a management tool has no reason to be visible to the whole world.
- Unencrypted traffic: a site without a certificate, or with an expired one, exposes the credentials that pass through it.
The solution: six layers, in this order
1. Sign in with a key, never a password
Administrative login uses a cryptographic key stored on the administrator's computer, not a password. The "root" account can no longer log in directly. You work with a named account and only switch to administrator for the action that requires it.
2. A firewall that denies everything by default
The starting rule is simple: everything that comes in is refused, except what you explicitly allow. On my servers, only one or two doors stay open to the public in the end. Everything else does not exist, as seen from the internet.
3. A guard that bans the persistent ones
Fail2Ban reads the login logs and temporarily blocks the addresses that pile up failures. It does not replace the key, but it cuts short repeated attempts and keeps the logs readable.
4. An encrypted tunnel for everything internal
Admin pages, dashboards and technical access to the server go through a WireGuard VPN. From the internet, these services are invisible; from the computer or phone of a colleague connected to the tunnel, they respond normally. This is the layer that changes the situation the most: a service nobody can see cannot be attacked from outside.
5. Tidy, isolated containers
Each application runs in a Docker container, grouped with its dependencies in a separate network. An application's database can only be reached by that application. Above all, you check that Docker does not quietly open what the firewall closes: it is the most common trap.
6. A single, encrypted web front door
Public sites and applications all go through a reverse proxy, Caddy in my case, which obtains and renews HTTPS certificates on its own. The applications themselves are never exposed directly: one monitored door rather than ten.
Why the order matters
Each layer assumes the previous one. Closing the firewall before you have a working key risks locking yourself out. Installing Docker before checking the firewall opens doors without your knowing. And installing the application first leaves it exposed for the whole duration of the work, often much longer than planned. Securing first takes only a few hours, and those hours cannot be made up afterwards.
What I learned running it
- Test access before closing the door. Every restriction is applied with a second session open, and you check that you can still get in before closing the first one. And you note where the hosting provider's rescue console is: the day the VPN goes down, that is what gives you control back.
- The firewall does not see everything. Docker's own documentation says so: a port published by a container bypasses the rules of the most common firewall on Ubuntu. So I publish internal services only on the local interface or on the VPN, and I check from outside what actually responds.
- A network setting can blind the guard. On one of my servers, a Docker configuration made every IPv6 visitor appear under the same internal address. By banning a single attacker, Fail2Ban would have blocked all those visitors at once. I spotted it by checking the addresses actually received, before it happened.
- What does not need to be public should not be. In 2026, I moved the admin interface of my management system behind the VPN. Customers lose nothing, and that page has disappeared from the bots' view.
Under the hood (for your IT person)
- SSH: PermitRootLogin no, PasswordAuthentication no, key-only authentication, low MaxAuthTries; once the VPN is validated, the daemon only listens on the tunnel address (watch out for systemd socket activation on recent Ubuntu releases).
- Firewall: UFW denying incoming traffic by default; only the WireGuard UDP port and, if needed, HTTP and HTTPS stay public.
- Fail2Ban: sshd jail, VPN range and loopback allowlisted; check that the address seen in the logs really is the client's.
- Docker: publish internal ports on 127.0.0.1 or on the VPN address, never on all interfaces; one network per group of applications; Docker starts after the network and the tunnel.
- Reverse proxy: Caddy, automatic HTTPS with renewal, internal routes restricted to VPN addresses.
- Account separation: a human account with admin rights, a service account with no sudo and no SSH key for automation.
What I take away
A secure server is not the one with the most security tools, it is the one that shows the least to the internet. A key instead of a password, a firewall closed by default, a tunnel for internal services, a single encrypted web door: this foundation takes a few hours and protects everything you install on it afterwards. It is also what an Ansible recipe replays identically on every new server. For the corporate VPN appliance, another door exposed by nature, read my article on corporate VPNs; for the passwords and keys this server will have to keep, the next step is secrets management.
Going further
I can audit an existing server, check from outside what it really exposes, or set up this foundation with you on a new machine. See Your tools and your data, or book a 20-minute discovery call.
The step-by-step guide
If your IT person wants to do it themselves, guide 1 in the Open Source Server Stack series, a secure server from A to Z (CHF 39), walks through all nine phases with the commands and a check at the end of each one: key-based access, firewall, Fail2Ban, WireGuard VPN, Docker and its networks, Caddy reverse proxy with automatic certificates, separate human and service accounts. Allow 3 to 5 hours of work, and you end up with a server you can leave connected without worrying.
The Guides Pack (CHF 149) brings together guides 0 to 8 of the series: a complete stack, documented and tested in production, from a bare server to backups, secrets and monitoring. If you would rather have support, the assisted installation (CHF 597) installs the foundation with you in one or two video sessions, Complete Pack included, with 60 days of email support.
Sources
- OpenSSH, sshd_config(5), official manual, accessed 15 November 2026.
- Docker, Packet filtering and firewalls (Docker and ufw), official documentation, accessed 15 November 2026.
- Fail2Ban, official repository, accessed 15 November 2026.
- WireGuard, official website, accessed 15 November 2026.
- Caddy, Automatic HTTPS, official documentation, accessed 15 November 2026.
- Photo: Carl Lender / Wikimedia Commons (commons.wikimedia.org), licence CC BY 2.0.
Tags: server security, SSH, firewall, Fail2Ban, WireGuard, Docker, Caddy, self-hosting, SME