Launch your first machine
This walkthrough takes one fresh Ubuntu server and turns it into a hardened LXD host. Budget about twenty minutes, most of it waiting on package installs.
You'll need:
sginstalled on your workstation.- A server running Ubuntu 24.04 (or 22.04) that you can SSH into as root with a key. We'll use
203.0.113.10. - A Tailscale auth key. Make one in the Tailscale admin console under Settings → Keys. A reusable key is handy if you're doing three machines.
1. Make a project directory (1 minute)
Everything for this estate lives here, including the ledger sg will create at .sg/state.db.
mkdir -p ~/estates/lab && cd ~/estates/lab
2. Trust the host key (1 minute)
sg checks every connection against ~/.ssh/known_hosts and never adds to it. SSH in once yourself, compare the fingerprint with your provider's console, and accept it:
ssh -i ~/.ssh/id_ed25519 [email protected] true
If that logs in without a prompt the second time, you're set.
3. Write the spec (2 minutes)
sg machine init asks for the essentials and writes a machine.yaml with every default filled in. Pass flags to answer the questions up front:
sg machine init --name node-a --address 203.0.113.10 \
--key-path ~/.ssh/id_ed25519 \
--deploy-public-key-path ~/.ssh/id_ed25519.pub \
--distro ubuntu-24.04 --output node-a.yaml
wrote node-a.yaml — 4 sections, sane defaults filled in.
Edit it, then run: sg machine init --config node-a.yaml
Leave out a flag and init asks for it instead. The two key questions are worded carefully, because they're the most common mistake:
bootstrap SSH PRIVATE key path (controller-local connection key)?is the keysglogs in with.deploy user PUBLIC key path (authorized key installed on target)?is the key that goes onto the server for thedeployuser. Its suggested default is the private path plus.pub.
Open the file. It's long because every default is written out:
api_version: genesis/v1
machine:
name: node-a
address: 203.0.113.10
ssh:
user: root
key_path: ~/.ssh/id_ed25519
distro: ubuntu-24.04
bootstrap:
packages:
- fail2ban
- unattended-upgrades
ssh_hardening:
password_root_login: false
password_authentication: false
deploy_user:
name: deploy
key_path: ~/.ssh/id_ed25519.pub
firewall:
guard: true
lxd_api_allow_from: []
lxd_api_allow_all_tailnet: false
tailscale:
enabled: true
auth_key_env: TS_AUTHKEY
lxd:
channel: 5.21/stable
api_address: tailnet:8444
storage:
driver: zfs
pool_file_size: 150GiB
arc_max: 4GiB
network:
bridge: lxdbr0
subnet: ""
nat: true
ipv6: none
profiles:
- name: default
- name: task-vm
cpu: 2
memory: 4GiB
The two you're most likely to change:
lxd.storage.pool_file_size: the ZFS pool is a sparse file on the root disk.150GiBis too big for a small VPS. Pick something that fits with room to spare, like40GiBon an 80 GB disk.bootstrap.firewall.lxd_api_allow_all_tailnet: set it totrueif you want to reach the LXD API or web UI from your workstation over the tailnet. Otherwise nobody can, which is the safe default.
Every field is explained in the machine.yaml reference.
4. Register it (1 minute)
Registration validates the file and records the machine in the ledger. It doesn't contact the server.
sg machine init --config node-a.yaml
node-a.yaml: valid (genesis/v1). registered node-a in the project ledger.
next: sg machine plan --config node-a.yaml
The first command in a new directory also creates .sg/state.db and prints a few goose migration lines. That's normal.
5. Plan (2 minutes)
Now sg connects and looks around. It uploads nothing, changes nothing and records no history.
export TS_AUTHKEY=tskey-auth-... # plan refuses if the variable is unset or empty
sg machine plan --config node-a.yaml
On a fresh server, expect all eight changes, each with a reason and a risk grade:
Machine node-a (203.0.113.10) — 8 changes to apply, 0 converged.
1 install.packages package fail2ban not installed [low]
2 harden.ssh effective sshd password authentication diverges [medium]
3 create.deploy-user deploy user absent [medium]
4 install.tailscale tailscale not installed [medium]
5 firewall.guard sg_guard table absent [high]
6 storage.zfs sg-zfs.conf absent [low]
7 install.lxd lxd snap not installed; Starting LXD sets kernel.apparmor_restrict_unprivileged_userns=0; … [high]
8 verify.isolation depends on guard verification [none]
Your reasons will describe your server. Read them. A row you didn't expect is the cheapest bug you'll ever catch.
6. Create (10 to 15 minutes)
sg machine create --config node-a.yaml
create builds a fresh plan (it never reuses the one you just read), shows it with an (executable) marker per row, and asks:
Machine node-a (203.0.113.10) — plan: 8 changes, 8 executable now, 0 deferred.
1 install.packages package fail2ban not installed [low] (executable)
…
Apply 8 changes to node-a? [y/N]:
Type y. Anything else prints declined: no changes applied and exits 0.
The changes run in order and each is verified before the next starts. When it's done:
run <run-id> finished: ok. 8 changes applied and verified.
If a change fails, the run stops there and records it:
stopped: run <run-id> failed. 5 applied, 1 failed, 2 not attempted.
fix the host, then re-run: sg machine create --config node-a.yaml
Fix what it names and run create again. Changes that already landed are seen as converged and skipped.
7. Check it (1 minute)
sg machine status --config node-a.yaml
status reports what's recorded, when each change was applied and any drift between the ledger and the host. It never repairs anything. Running plan again should now say:
Machine node-a — converged; no changes to apply.
The server is now on your tailnet. tailscale status on your workstation lists it with its 100.x.y.z address. You'll need that address to form a cluster.
What next
- Do it two more times (
node-b,node-c) and form a cluster. Applications need one. - See Machine examples for smaller pools, tailnet access to the LXD UI and other setups.
- Learn how to roll back or destroy a machine.