From an empty VPS to a secure web server
User, keys, quantum-safe key exchange, updates, time, firewall, nginx, DNS and fail2ban — in the order you need them.
A freshly ordered server is a machine with a public address and a root password that arrived by email. Turning it into a web server that runs for years takes twelve steps. The order is not arbitrary: whoever switches on the firewall before the key locks themselves out; whoever fetches the certificate before the name entry gets none.
I start from Ubuntu 26.04 LTS, available since April 2026. The commands also work
on 24.04 — there, step 5 does not yet have the quantum-safe exchange switched on,
and in step 7 the time service is called systemd-timesyncd instead of chrony.
What you need
- A VPS with Ubuntu 26.04 LTS; 2 GB of RAM is enough for this. When ordering,
pick the Ubuntu image, not plain Debian — the guide relies on Ubuntu’s defaults
(networking, time service,
ufw). - The public address the provider assigns. This text uses
203.0.113.10. - A domain whose records you can change. In this text it is
example.com. - Your own machine with an SSH client. Linux and macOS have one; on Windows it comes with PowerShell.
Which address serves as the example here. example.com is one of the domains
IANA keeps for documentation: not registrable, but expressly allowed as an example
in texts (IANA,
RFC 2606). The address 203.0.113.10
comes from 203.0.113.0/24, the range RFC 5737 reserves for examples
(RFC 5737); it belongs to nobody and
cannot be reached on the internet. When you rebuild this, you put your own address
and your own domain everywhere.
1. The first login
The provider sends credentials or shows them in its panel. The first way in is as
root:
ssh root@203.0.113.10
On the first connection SSH asks you to confirm the fingerprint. Comparing it is
worth the effort if the provider displays it; afterwards it sits in
~/.ssh/known_hosts and the question does not return.
On the server, check what actually runs there:
cat /etc/os-release
You expect VERSION="26.04 LTS (Resolute Raccoon)". Then bring everything the
provider shipped up to date:
apt update && apt full-upgrade -y
2. The user
You work as root only as long as there is no other way. So create a user:
adduser gustl
usermod -aG sudo gustl
adduser asks for a password. For logging in it becomes dispensable in a moment,
for sudo it stays useful. Whoever wants to shorten even that can add NOPASSWD
for sudo; it gets more convenient, not safer.
From here on, work as this user in a second session:
ssh gustl@203.0.113.10
3. The key
Passwords can be guessed, keys cannot. On your own machine, create a key pair:
ssh-keygen -t ed25519 -C "gustl@laptop"
Without a passphrase the key is as well protected as the machine it lies on; with
one it takes both. The private part then lives in ~/.ssh/id_ed25519, the public
part next to it with .pub. The public part goes onto the server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub gustl@203.0.113.10
After that, logging in works without a password — with the key and, if set, with the passphrase.
4. No password, no root
The OpenSSH configuration lives in /etc/ssh/sshd_config and additionally reads
everything from /etc/ssh/sshd_config.d/. Your own settings belong in a file of
their own, so that a package update does not overwrite the defaults:
sudo tee /etc/ssh/sshd_config.d/99-security.conf > /dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowUsers gustl
EOF
What the lines do: root can no longer log in, passwords are no longer accepted,
only keys, and only that one user gets through at all.
Before restarting, check that the file is understood:
sudo sshd -t && echo "configuration is fine"
Then reload — do not close the old session before the new one works:
sudo systemctl reload ssh
On Ubuntu, SSH starts through a socket; every new connection reads the
configuration anyway. The reload does no harm and makes sure the running
instance is up to date as well.
Test in a second window:
ssh gustl@203.0.113.10 # must work
ssh -o PubkeyAuthentication=no gustl@203.0.113.10 # must fail
ssh root@203.0.113.10 # must fail
If one of these turns out differently than expected, only the provider’s console helps. That is why the first session stays open.
5. Quantum-safe key exchange
Key exchange is the part of an SSH connection that would be vulnerable to a
quantum computer: an attacker could record it and compute later. Since version
10.0, OpenSSH uses a hybrid method by default, mlkem768x25519-sha256
(OpenSSH 10.0).
Ubuntu 26.04 ships OpenSSH 10.2p1 (package). That means: the quantum-safe exchange is already switched on and you do not have to do anything. You can verify it in two places — on the client, which methods it knows:
ssh -Q kex | grep -E "mlkem|sntrup"
and during the handshake, which one was actually chosen:
ssh -v gustl@203.0.113.10 2>&1 | grep "kex: algorithm"
# debug1: kex: algorithm: mlkem768x25519-sha256
If you want to pin it, put it in the same file as above:
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512@openssh.com,curve25519-sha256
The catch: older clients do not know the first method and then cannot get through. That is exactly why the default is better than pinning today — it takes the best method both sides can do.
What is not quantum-safe here yet are the signatures. The keys with which
server and client identify themselves are Ed25519. A quantum-safe signature
algorithm (ssh-mldsa44-ed25519) only arrived with OpenSSH 10.4 as an experiment
and is switched on by default from 10.6
(OpenSSH 10.4,
OpenSSH 10.6). Ubuntu 26.04 has
10.2 — the signature side therefore stays classical for now. Whoever wants both
builds OpenSSH themselves; the commands are in the article
SSH against quantum computers.
6. Automatic updates
Ubuntu ships unattended-upgrades and switches it on during installation
(Ubuntu Server).
Check whether it runs:
systemctl status unattended-upgrades --no-pager
cat /etc/apt/apt.conf.d/20auto-upgrades
You expect "1" twice — once for the package lists, once for installation. If the
file is missing:
sudo dpkg-reconfigure --priority=low unattended-upgrades
By default, security updates are applied. Two things are a matter of taste and
live in /etc/apt/apt.conf.d/50unattended-upgrades:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
Without these lines, a kernel update is still installed, but the running kernel stays active until the next reboot. With them, the server restarts at half past three in the morning when necessary — for a web server that is the quieter way, as long as nobody wants anything from it at that hour.
What happened is then in the log:
sudo unattended-upgrade --dry-run -d
ls -l /var/log/unattended-upgrades/
7. Time
Timestamps in logs, validity of certificates, one-time codes: all depend on a
clock that is right. Since Ubuntu 25.10 that is the job of chrony, not
systemd-timesyncd. Ubuntu sets it up with NTS, authenticated time transfer
(Ubuntu Server).
The state in two commands:
timedatectl
chronyc -N tracking
System clock synchronized: yes and a reference server in the first line are
enough as proof. Which sources are configured is in
/etc/chrony/sources.d/ubuntu-ntp-pools.sources; the Ubuntu pools are marked with
nts and prefer there. Whoever wants their own servers adds them in a separate
file in the same directory and leaves the Ubuntu file alone.
Whether the connection really is authenticated is shown by:
sudo chronyc -N authdata
If the Mode column says NTS, the source is checked not only in time but in
origin. That does not replace trust in the provider — it only rules out someone
forging the answer along the way.
8. Firewall
ufw is the obvious simple way on Ubuntu to limit the incoming connections:
forbid everything incoming, allow three ports.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status verbose
Before ufw enable the SSH rule must be in place, otherwise the session is
gone. Check:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80,443/tcp ALLOW Anywhere
The ports appear as numbers here because nginx is installed in the next step —
the package only brings its ufw profile along with it. If you only want
encrypted delivery, open 443 alone and leave 80 open as long as Certbot renews the
certificate.
9. nginx
sudo apt install nginx
systemctl status nginx --no-pager
curl -I http://203.0.113.10
The last line shows HTTP/1.1 200 OK with the default page. It comes from
/etc/nginx/sites-enabled/default, which is no longer needed:
sudo rm /etc/nginx/sites-enabled/default
For your own site, create a file:
sudo tee /etc/nginx/sites-available/example.com > /dev/null <<'EOF'
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
EOF
sudo mkdir -p /var/www/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
nginx -t checks the file before it takes effect. reload swaps the configuration
without tearing down connections.
A test page, so the empty directory listing does not appear:
echo "<h1>It works.</h1>" | sudo tee /var/www/example.com/index.html
10. DNS
The name entry belongs to the domain provider, not the server. One A record is needed:
| Type | Name | Value | TTL |
|---|---|---|---|
| A | @ |
203.0.113.10 |
300 |
In the “Value” column you enter your own address when rebuilding, not the one
from the table. A second record of type AAAA is added if the server has an IPv6
address. The
short validity of 300 seconds is pleasant while setting up; later it may be longer.
Check whether the records have arrived:
dig +short example.com
dig +short AAAA example.com # only if an AAAA record exists
If 203.0.113.10 comes back, the rest is a matter of minutes. If it does not,
it is almost always the wrong name server or a typo in the name.
11. The certificate
Without TLS a web server does not belong on the internet today. Certbot fetches the certificate and enters it in the nginx configuration:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
Certbot changes the file in sites-available itself and sets up renewal. Check:
systemctl list-timers | grep certbot
sudo certbot renew --dry-run
The second command rehearses the renewal without using anything up. It should pass before you rely on it.
12. fail2ban
Anyone running a server with an open SSH port gets login attempts from machines
that know nobody. And anyone running a web server gets requests for files that
never existed there: /.env, /.git/config, /wp-login.php. fail2ban reads
both and blocks addresses that try too often.
sudo apt install fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshd
The SSH jail is already enabled with the package; the two status commands show
whether it runs and whom it has blocked. For the web server a jail on the access
log is added — nginx writes into files, not into the journal:
sudo tee /etc/fail2ban/jail.d/nginx.conf > /dev/null <<'EOF'
[nginx-botsearch]
enabled = true
backend = auto
port = http,https
logpath = /var/log/nginx/example.com.access.log
maxretry = 5
findtime = 10m
bantime = 1h
EOF
sudo systemctl restart fail2ban
Whether the filter recognises your own log lines at all can be measured beforehand, without banning anyone:
sudo fail2ban-regex /var/log/nginx/example.com.access.log \
/etc/fail2ban/filter.d/nginx-botsearch.conf
That is the basic kit. What goes beyond it — the line without which the SSH jail
looks into an empty journal, ban levels for repeat offenders, a filter of your own
against scans, and the proof with fail2ban-regex — is in the article
checking fail2ban.
Checklist
| Check | Command | Expectation |
|---|---|---|
| Login with key only | ssh -o PubkeyAuthentication=no gustl@… |
refused |
| root blocked | ssh root@… |
refused |
| Quantum-safe exchange | ssh -v … 2>&1 | grep "kex: algorithm" |
mlkem768x25519-sha256 |
| Updates run | systemctl status unattended-upgrades |
active (running) |
| Time is right | timedatectl |
synchronized: yes |
| Firewall | sudo ufw status |
active, OpenSSH and 80/443 |
| Web server | curl -I https://example.com |
200, valid certificate |
| Bans | sudo fail2ban-client status sshd |
jail active |
What is still missing
A server that runs is not the same as a server that is maintained. What is not here and still belongs: a backup you can actually restore, a look at the logs every few weeks, and a second machine where restoring was practised once. For a start, the list above is enough.
What this article deliberately does not do:
- No backup. Without one, every server is an outage with an announcement. What a backup looks like that you can actually open is in the article Passwords do not belong in someone else’s hands.
- No monitoring. Otherwise you notice that the site stopped answering when someone calls.
- No different SSH port. A port other than 22 reduces the number of attempts in the log and moves the problem instead of solving it.
- No AppArmor profiles, although Ubuntu ships them.
- No firewall at the provider. A second layer in front of the server costs nothing and catches what the server itself no longer sees.
- No TLS hardening. The defaults of Certbot and nginx are fine; whoever wants more needs HSTS, its own cipher lists and a look at the logs.
- No applications outside apt. A container image does not update itself
through
unattended-upgrades.
Where to go next
Two things from this guide have an article of their own, because they need more room than a step allows:
- Quantum-safe signatures. Ubuntu 26.04 ships OpenSSH 10.2, which does not
yet contain
ssh-mldsa44-ed25519. Whoever wants quantum-safe identities too builds OpenSSH 10.6 or later from source — with checksums, its own installation and a way back if something sticks: SSH against quantum computers. - Passwords. A keyring of your own on the same server is the next step after the web server: Vaultwarden, a certificate, a backup you can open — and the question of what a breach at a provider means: Passwords do not belong in someone else’s hands.
And if you would rather commission this than do it yourself: we set up servers, from the first login to the certificate, and answer a message through the contact form — the subject is already filled in.
Sources
All addresses retrieved on 28 November 2026, each answered HTTP 200.
- Ubuntu 26.04 LTS, release notes: https://documentation.ubuntu.com/release-notes/26.04/
- Ubuntu Server, automatic updates (
unattended-upgrades,20auto-upgrades,50unattended-upgrades): https://documentation.ubuntu.com/server/how-to/software/automatic-updates/ - Ubuntu Server, time synchronisation with
chronyand NTS: https://documentation.ubuntu.com/server/how-to/networking/chrony-client/ - Ubuntu Server, firewall with
ufw: https://documentation.ubuntu.com/server/how-to/security/firewalls/ - OpenSSH 10.0 —
mlkem768x25519-sha256as the default key exchange: https://www.openssh.com/txt/release-10.0 - OpenSSH 10.4 —
mldsa44-ed25519as an experiment, keys viassh-keygen -t mldsa44-ed25519: https://www.openssh.com/txt/release-10.4 - OpenSSH 10.6 —
ssh-mldsa44-ed25519switched on by default: https://www.openssh.com/txt/release-10.6 - Ubuntu package
openssh-serverin 26.04 (1:10.2p1): https://packages.ubuntu.com/resolute/openssh-server - nginx, beginner’s guide: https://nginx.org/en/docs/beginners_guide.html
- fail2ban, manual page
jail.conf(structure ofjail.local): https://manpages.ubuntu.com/manpages/resolute/man5/jail.conf.5.html - Certbot, instructions and renewal: https://certbot.eff.org/instructions
- IANA, example domains (
example.comandexample.orgfor documentation): https://www.iana.org/help/example-domains - RFC 2606, reserved top-level names and example domains: https://www.rfc-editor.org/rfc/rfc2606
- RFC 5737, address ranges for examples (
203.0.113.0/24, TEST-NET-1): https://www.rfc-editor.org/rfc/rfc5737