Machines overview

A machine is one Ubuntu server that sg has turned into a hardened LXD host. You describe it in a machine.yaml, and sg machine create gets it there one verified change at a time.

What happens to the server

sg machine create applies up to eight changes, always in this order. Each one is checked after it runs; the run stops and records the failure if a check doesn't pass.

#ChangeWhat it doesRisk
1install.packagesInstalls fail2ban and unattended-upgrades (or your list).low
2harden.sshTurns off password logins and root password login, and checks the effective sshd policy.medium
3create.deploy-userCreates the deploy user with your public key and non-interactive sudo.medium
4install.tailscaleInstalls Tailscale and joins your tailnet with the auth key from your environment.medium
5firewall.guardLoads an nftables guard (sg_guard) so the LXD API is reachable only on the tailnet.high
6storage.zfsWrites /etc/modprobe.d/sg-zfs.conf to cap the ZFS ARC, so storage can't starve the host.low
7install.lxdInstalls the LXD snap (held on 5.21/stable), creates the file-backed storage pool, bridge and profiles, and binds the API to tailnet:8444.high
8verify.isolationBoots a throwaway VM (sg-isolation-<run>), checks what it can and can't reach, then deletes it. Leaves nothing behind.none

A change that is already in the right state is skipped. Run create on a converged machine and it tells you there's nothing to do.

The verbs

CommandEffect
sg machine initLocal only. Writes a machine.yaml by asking questions, or registers one you wrote with --config.
sg machine planRead-only. Connects over SSH and prints the ordered changes.
sg machine createChanges the host. Applies the plan after you confirm.
sg machine statusRead-only. Reports recorded state, drift and last-applied times. Never repairs.
sg machine rollbackChanges the host. Undoes the last run's reversible changes.
sg machine destroyChanges the host. Removes everything sg recorded, in reverse order.

What it needs

  • Ubuntu 22.04 or 24.04 LTS, reachable over SSH as root with your key.
  • The host key in your ~/.ssh/known_hosts. sg never edits that file.
  • A Tailscale auth key in an environment variable (TS_AUTHKEY by default).

What it never does

  • Reboot the host. If a reboot is pending, it says so and leaves it to you.
  • Bind the LXD API to port 8443, a wildcard or loopback.
  • Delete the ZFS pool or LXD on a rollback. Those hold data; only destroy removes them.

Where to next