LZLZL/AI toolchain/Cloud · Hardening
FREEMedium · Practice D · Cloudhardening

The first hour:
the order does not reverse

2026-08-21 · Five moves, and reversing them locks you out

A public machine is being scanned from its first minute — that is not rhetoric, it is the default. So the first hour is not for installing things. It is for closing the door. Five moves, with strict dependencies.

In this pagefive moves in order, three classic lockouts. Not in this pageany of my own machines' configuration. Everything here is a placeholder.

1Five moves, in this order

#MoveWhy it sits here
1Confirm key login worksEverything after this can lock you out. This is your way back in
2Create a non-root user with sudoMust exist before root login is closed, or nobody can get in
3Disable password login (and direct root login)Scanners are overwhelmingly trying passwords. Highest-yield step
4Firewall: default deny, open only what is neededSet before installing services, or you will miss ports you just opened
5Failure banning (fail2ban and similar)Backstop. Limited value if the above is right, but it is cheap
Why the order does not reverse

Every step removes a way in. Disable password login before setting up keys and for that window you have no way in at all — on a machine in someone else's datacentre.

One rule: confirm the new way in works before closing the old one. That holds for every later operations change too, not just the first hour.

2Three classic lockouts

One: editing the SSH config, then disconnecting

Change the config, restart SSH, close the terminal — and the new config has an error, and that is that.

Correct form: keep your current session open and open a second connection to verify. Only when the new one works do you close the old. The old session is your safety line.

Two: default-deny firewall without allowing SSH first

The instant the inbound policy flips to deny, your own SSH is denied with everything else.

Correct form: add the SSH allow rule, then change the default. Same shape — open the new door before closing the old one.

Three: a non-root user with no sudo

Create the user, disable root login, discover the new user can do nothing.

Correct form: verify immediately after creating — log in as the new user, run something requiring sudo, confirm it works, then close root.

All three have identical structure: the old path was closed before the new one was verified. Remember that and you need no specific commands from this page.

3Firewall: open only ports you can name

PortOpen?
SSHYes — your only entrance
Services you genuinely serve publiclyYes
Everything elseNo
⚠ Anything for your own use should not listen publicly

Always-on agents, databases, admin panels should bind to localhost only, not to the public interface. Many programs default to listening on everything — which means one hole in the firewall exposes them.

Do both layers: bind locally (first) and firewall it too (second). With only the firewall layer, one mistaken rule exposes everything.

4After the first hour: three ongoing things

ThingHow
System updatesAt minimum enable automatic security updates. An unpatched machine makes the firewall moot
Log rotationPrevious page: day one, or the disk fills eventually
Know who logged inGlance at the login records occasionally. No monitoring stack needed — just look

5Write the hour down

Notes taken as you go are your rebuild script

You will open another box eventually — new provider, new region, or because this one died. At that point this note is worth far more than the ten minutes it cost.

One discipline while writing: steps only, no secrets and no real addresses. The note will likely end up in your backup, possibly in a repository. Write the variable parts as placeholders and substitute when using it — which is also the starting point for page 22's "rebuild in one command".

Nature of this page The five-step order and its dependencies are general server hardening practice, not a distribution-specific tutorial — exact commands vary; use your distribution's own documentation.
The core rule "Confirm the new way in works before closing the old one" — all three lockout cases are violations of exactly that.
Not in this page My own SSH configuration, open ports, usernames or firewall rules. Everything here is a placeholder.

RelatedRead next

D · Cloud
Run it as a service, so it restarts itself
D · Cloud
Buying a box: sizing and region
D · Cloud
Key isolation, monitoring, backups, switching off
C · Always-on
Telegram: lock down who, then discuss what
An educational and engineering record — not a review or endorsement of any third-party product. Commands, config keys, prices and terms are per each vendor's official docs; this page states when it was checked and all of them can change without notice — verify before you copy anything. Self-hosting is your own responsibility: keys, accounts and data are on you.