Interactive Ubuntu golden-path hardening CLI — born from a real production VPS mission (ZENORA), industrialized for the next ones.
Not a silent magic one-liner. An operator-in-the-loop accelerator: prompts first, ordered phases second, checkpoints before anything that can lock you out.
Replaying a 12-phase fortress by hand on every client VPS is slow and forgetful. This repository encodes that battlefield-proven path as a modular Bash product:
- Core always on: SSH fortress, patches, unattended-upgrades, sysctl, UFW, Fail2Ban, AIDE/Lynis baseline, NTP, ops finalize
- Optional on demand: Docker, Nginx, Naxsi, CSF, CrowdSec, Cloudflare helpers, monitoring
- Anti-lockout first: dual-port SSH cutover,
sshd -Tasserts, automatic rollback - Resumable & auditable: state files, safe config export, timestamped logs, backup manifests
- Honest dry-run / doctor: no fake “done” markers; reports measure effective state
Origin mission: ZENORA Ubuntu production hardening. Product id in the author portfolio: interactive script industrialization of that runbook.
git clone https://github.com/barthez-kenwou/linux-server-hardening.git
cd linux-server-hardening
sudo ./harden.shUseful variants:
sudo ./harden.sh --profile web # Nginx + CrowdSec + Cloudflare helpers
sudo ./harden.sh --profile fortress # Full stack including CSF + Docker
sudo ./harden.sh --profile minimal # Bastion-style core only
sudo ./harden.sh --dry-run --profile web --show-plan
sudo ./harden.sh --resume # After reboot / interrupted run
sudo ./harden.sh --doctor # Effective posture diagnostics
sudo ./harden.sh --rollback ssh # Restore SSH from latest backup| Item | Requirement |
|---|---|
| OS | Ubuntu 22.04 or 24.04 LTS |
| Privileges | root / sudo |
| Access | Working SSH (or console) before lockdown |
| Network | Outbound HTTPS for package / CrowdSec / CSF downloads |
| Operator | Human judgment — this tool assists, it does not replace you |
CLI splash → preflight → interactive interview
↓
ordered modules (core + selected optionals)
↓
backups + logs + exported config + final report
| Layer | Modules |
|---|---|
| Core | baseline, SSH, updates, unattended-upgrades, tools, NTP, sysctl, UFW, iptables extras, Fail2Ban, AIDE/Lynis, ops finalize |
| Optional | Docker, Nginx, Naxsi, CSF, CrowdSec, Cloudflare, monitoring |
Deep dive: docs/ARCHITECTURE.md · phase map: docs/PHASES.md · anti-lockout: docs/ANTI_LOCKOUT.md
The script asks (with short necessity briefs):
- Profile (
minimal/web/fortress/custom) - Hostname & timezone
- Admin SSH usernames (
AllowUsers) - SSH port
- Alert email (AIDE / reports)
- Trusted admin IP/CIDR
- Optional modules: Docker, Nginx (+ Naxsi), CSF, CrowdSec, Cloudflare, monitoring
Silent installs that “assume fortress” are how people brick production. Defaults stay conservative; optionals are opt-in.
harden.sh # Entry point
lib/ # UI, prompts, logging, system helpers
modules/ # Ordered phase implementations
templates/ # sshd, sysctl, fail2ban, nginx, monit, …
profiles/ # minimal | web | fortress
config/ # Documented default knobs
docs/ # English documentation
scripts/doctor.sh # Health / posture check
tests/syntax-check.sh # bash -n across the tree
- Config files are backed up under
backups/<timestamp>/with aMANIFEST.txt - SSH uses dual-port listen → proven second session → final lockdown →
sshd -Tasserts - Failed SSH cutover triggers
--rollback sshautomatically - UFW enable and CSF production cutover require typing
YES; CSF reload is verified before disabling UFW --dry-rundoes not write to/etc,state/, orbackups/--non-interactiverefuses critical steps unless--force-yes(explicit foot-gun)- Profiles / last-run files are parsed as KEY=value — they are never
sourced as shell
- Edit templates in
templates/ - Add a profile under
profiles/myorg.confand run--profile myorg - Pass
--config path/to/file.conffor automation labs - See
docs/CUSTOMIZATION.mdanddocs/MODULES.md
Validated on clean lab VMs, local Ubuntu environments, and real friend VPS runs — enough confidence for missions, enough humility to keep prompts and checkpoints.
This is not a substitute for human judgment on critical production.
| Doc | Topic |
|---|---|
| ARCHITECTURE.md | Design, flow, module contracts |
| PHASES.md | Golden-path phase map |
| ANTI_LOCKOUT.md | SSH / FW lockout prevention |
| MODULES.md | Per-module reference |
| CUSTOMIZATION.md | Profiles, templates, hooks |
| OPERATIONS.md | Day-2 supervision |
| TROUBLESHOOTING.md | Common failures |
| SECURITY.md | Vulnerability reporting |
| CONTRIBUTING.md | Contribution guide |
MIT © Barthez Kenwou
- Field origin: ZENORA Ubuntu VPS hardening mission
- Productization: this repository — interactive golden path for future client missions