Skip to content

GaiaOpen source project

A fresh Linux server, hardened with a single command.

An administrator account with SSH keys, locked-down SSH, a firewall that closes everything that does not need to be open, fail2ban, automatic security updates, kernel and network hardening and a security audit before and after.

Status
In development
License
Apache-2.0
Language
Bash
Version
0.1.0

01Why Gaia

Every new server on the internet gets login attempts within minutes.

The checklist to make it reasonably safe is always the same and easy to get wrong by hand: a forgotten AllowUsers, a firewall enabled before SSH was allowed, a Docker container publishing a port that ufw never sees. Gaia encodes that checklist in a verifiable way.

  • 01Secure by defaultNo root login, no SSH passwords, inbound traffic denied.
  • 02No lock-outsThe SSH configuration is validated with sshd -t and checked with sshd -T before it takes effect; if anything does not match, it is rolled back. The firewall allows SSH before it is enabled.
  • 03TransparentEvery action is a log line; secrets are masked; --dry-run shows exactly what would change.
  • 04MeasurableLynis runs before and after and shows the hardening index gain. Listening ports are audited at the start and at the end, pointing out what is exposed to the internet.
  • 05IdempotentRunning it again only fixes what drifted.

02What it does

Twenty steps, from preflight to summary.

  1. 01preflightroot, supported system, free disk, access to repositories, systemd; records what is listening (changes nothing)
  2. 02audit-beforebaseline Lynis audit (reference hardening index)
  3. 03packagesapt update, full-upgrade (configurable) and base packages
  4. 04timetime zone and NTP synchronization
  5. 05hostnamehost name in hostnamectl, /etc/hosts, preserved across cloud-init reboots
  6. 06admin-useradministrator account in the sudo group, with SSH keys (literal, from GitHub or imported from the provider)
  7. 07sshdrop-in with root and passwords off, modern crypto, AllowUsers, MaxAuthTries, LoginGraceTime; validated with rollback
  8. 08firewallufw denying inbound, SSH rate-limited (limit) and allowed before enabling, extra rules
  9. 09fail2bansshd jail on the configured port
  10. 10auto-updatesunattended-upgrades with security updates only; optional automatic reboot
  11. 11sysctlanti-spoofing, no redirects, SYN cookies, restricted kernel information
  12. 12journaldpersistent, compressed journal with a disk cap
  13. 13apparmorAppArmor enabled and loading profiles
  14. 14swapoptional swap file for small VPS, with low swappiness
  15. 15servicesturns off network services a server rarely needs (rpcbind, avahi, cups) and keeps the local mail server on loopback
  16. 16directoriesdirectories with owner and mode (e.g. /srv/apps)
  17. +modulesoptional software, already hardened
  18. +custom stepsyour own scripts in steps.d/
  19. 19audit-afterfinal Lynis audit, compared with the baseline
  20. 20summarywhat listens now, what was closed, and the next steps

03Before you run it

Four precautions before the first command.

  1. 01

    Have a public SSH key for the administrator account. Gaia accepts any of these sources, in this order:

    • --ssh-key "ssh-ed25519 AAAA... you@laptop" (or GAIA_ADMIN_SSH_KEYS in gaia.conf)
    • --github-keys your-user (imports https://github.com/your-user.keys)
    • the keys your VPS provider already placed in /root/.ssh/authorized_keys (imported automatically when no other key was given)
  2. 02

    Keep your current session open until you can log in with the new account from a second one.

  3. 03

    Open in your provider’s firewall (security group, cloud firewall) the same ports you allow in Gaia, such as 80/443 for a website.

  4. 04

    Run with --dry-run first.

04Quick start

From the repository or with the release installer.

from the repository · recommended
$ git clone https://github.com/Black-Ghost-Corp/Gaia-Bootstrapper.git$ cd Gaia-Bootstrapper# Interactive: asks for the administrator account and the modules.$ sudo ./bootstrap.sh# Non-interactive: everything on the command line.$ sudo ./bootstrap.sh --yes \    --admin-user alice \    --github-keys alice \    --modules docker,caddy \    --allow 80/tcp,443/tcp \    --hostname web-01.example.com \    --timezone America/Sao_Paulo \    --swap 2G
with the release installerfrom the first release on
$ curl -fsSL https://github.com/Black-Ghost-Corp/Gaia-Bootstrapper/releases/latest/download/install.sh | sudo bash# with options:$ curl -fsSL https://github.com/Black-Ghost-Corp/Gaia-Bootstrapper/releases/latest/download/install.sh \    | sudo bash -s -- --modules docker --admin-user alice --yes

The installer downloads the version and checks its SHA-256 (and its Ed25519 signature, when the release is signed) before running anything. The release lives in /opt/gaia/releases/<version> (linked from /opt/gaia/current), and an /opt/gaia/gaia.conf is used automatically when present.

Options

--modules LIST
optional modules, comma separated (e.g. docker,caddy; none or all)
--admin-user NAME
administrator account (default: the user who ran sudo)
--ssh-key KEY
administrator public key (repeatable)
--github-keys USER
import keys from https://github.com/USER.keys (repeatable)
--ssh-port PORT
SSH port (default 22)
--allow RULES
extra inbound firewall rules (e.g. 80/tcp,443/tcp)
--hostname NAME
host name
--timezone TZ
time zone (default UTC)
--swap SIZE
create a swap file (e.g. 2G)
--no-audit
skip the Lynis audit
--config FILE
configuration file (default: gaia.conf next to bootstrap.sh, if present)
--dry-run
show what each step would change, without changing anything
--only LIST
run only these steps
--skip LIST
skip these steps
--list-steps
list the steps
--yes, -y
do not ask anything

05Modules

Software installed already configured securely.

Choose them with --modules, with GAIA_MODULES in gaia.conf or from the interactive menu.

  • docker

    What it installs

    Docker Engine, compose and buildx from the official repository

    Hardening applied

    • GPG key checked by fingerprint
    • log rotation and live-restore
    • ports published by containers now obey ufw (DOCKER-USER chain), opened only through GAIA_DOCKER_PUBLISH
    • option to publish on 127.0.0.1 only
    • warning that the docker group is root-equivalent
  • caddy

    What it installs

    Caddy (reverse proxy with automatic HTTPS) from the official repository

    Hardening applied

    • key checked
    • Caddyfile validated with caddy validate before replacing it
    • HSTS, nosniff, Referrer-Policy, no Server header
    • internal paths blocked with 403
    • reload without dropping connections

06Configuration

Everything is optional.

For repeated use (several identical machines), copy the example and adjust. Invalid values are rejected before any step runs.

Precedence

  1. command line
  2. gaia.conf
  3. environment variables
  4. defaults
gaia.conf
$ cp gaia.conf.example gaia.conf$ chmod 600 gaia.conf$ sudo ./bootstrap.sh            # picks up ./gaia.conf automatically

07How it works

Validated before it takes effect. Logged after.

  • Idempotent stepsEach step ends with a status:doneokskippedfailedwould changenot selected
  • Files validated before they take effectCritical configuration (sshd, sudoers, fail2ban, ufw rules, Caddyfile) is written to a temporary file, validated by the tool itself and only then swapped in; if validation fails, the previous file stays.
  • Third-party repositories verifiedGPG keys are downloaded over HTTPS and compared with the expected fingerprint before any apt call.
  • LogsOutput on screen and in /var/log/gaia/gaia-<date>.log (mode 700), with secrets masked. A lock prevents two concurrent runs.[gaia][level][step=x] message key=value

08Custom steps

Your scripts, under the same contract.

Put executable scripts in steps.d/ (or in GAIA_EXTRA_STEPS_DIR). They run after the modules, receive the configuration and follow the same log, dry-run and status contract.

steps.d/
#!/usr/bin/env bash# gaia-description: creates the application’s docker networksource "$GAIA_LIB_DIR/common.sh"gaia_step_modedocker network inspect app >/dev/null 2>&1 || gaia_run docker network create app

09Compatibility

Ubuntu and Debian, amd64 and arm64.

SystemVersionsArchitectures
Ubuntu Server22.04 LTS, 24.04 LTS, 26.04 LTSamd64, arm64
Debian12 (bookworm), 13 (trixie)amd64, arm64

Requires Bash 5, systemd and root access. Inside containers the kernel, swap and AppArmor steps are skipped (they belong to the host).

10Development and testing

Tested without touching the machine.

The unit tests run the whole of Gaia against a fake root (GAIA_ROOT) with system commands replaced by simulators.

scripts/test.sh
$ scripts/test.sh               # bats (unit tests against a fake system) + shellcheck$ scripts/test.sh integration   # real run inside throwaway Ubuntu/Debian containers

11Roadmap

Next steps.

In rough order of priority. Suggestions and PRs are welcome: open an issue to discuss before starting something big.

Short term

  • auditd with baseline rules and AIDE (file integrity)
  • --check mode: only verifies compliance and exits non-zero on drift
  • Ready-made profiles (--profile web, --profile docker-host, --profile bastion)

New modules

  • Reverse proxies: hardened Nginx and Traefik
  • Containers: Podman and rootless Docker; k3s with a CIS configuration
  • Databases: PostgreSQL, MariaDB, Redis and MongoDB bound to loopback, with strong authentication and backups
  • Private access: Tailscale and WireGuard (SSH over the VPN only)
  • Active defense: CrowdSec as an alternative or complement to fail2ban
  • Observability: node_exporter, Netdata and Uptime Kuma behind the proxy, no public ports
  • Backups: restic or borg with scheduling and verification
  • Runtimes: Node.js, Python and Go through version managers
  • Isolated self-hosted CI runners
  • Alerts (e-mail, Telegram, Slack) for logins, bans and pending updates

Platforms

  • RHEL family (Rocky, AlmaLinux) with firewalld and SELinux
  • Cloud images: ready-to-use cloud-init user-data for the main providers
  • Own download mirror as an alternative to GitHub

12Project

Contributing, security and license.

  • Contributing

    Code and logs are in English, every change comes with bats tests and passes shellcheck, and nothing that changes the system may bypass --dry-run.

  • Security

    Found a vulnerability? Do not open a public issue. Follow the security policy and use GitHub private reporting.

  • License

    Distributed under the Apache License 2.0.

Gaia changes the security configuration of your server. It is provided "as is", without warranties; review the --dry-run output and test on a throwaway machine before using it in production.

Run it on your next VPS. Read the code first, if you like.