Hetzner Cloud
Operate Hetzner Cloud through the hcloud CLI. When in doubt about server types, prices, locations, images, or flag syntax, run the discovery command rather than rely on this file or pretraining — the CLI is current.
Authenticate
Generate a token in Hetzner Console → project → Security → API Tokens, then either:
hcloud context create <name> # interactive: stored in cli.toml, persists across shells
export HCLOUD_TOKEN="…" # CI/scripts: most commands read this automatically
hcloud context create is the one common case that still prompts even with the env var set — pass --token-from-env to skip the prompt in non-interactive sessions.
Health check: hcloud datacenter list.
Mental model
hcloud manages everything inside Hetzner Cloud: servers, networks, firewalls, load balancers, volumes, DNS zones, SSH keys, primary/floating IPs, snapshots, certificates, placement groups, storage boxes.
It does not manage:
- Hetzner Robot — dedicated/auction servers, separate product and API.
- Project creation, billing, team membership, API token issuing — web console only.
Discovery beats memorization. Pretraining ages; the CLI is current.
| Question |
Command |
| Server types and prices |
hcloud server-type list |
| Locations and datacenters |
hcloud location list |
| OS images |
hcloud image list --type system (add --architecture arm for ARM) |
| Command/flag details |
hcloud <resource> <verb> --help |
| Everything in this project at a glance |
hcloud all list |
| Is a server actually reachable? |
hcloud server describe <srv> -o json → public_net.ipv4.blocked (see gotcha 9) |
Structured output for scripts: --output json | jq …, --output columns=id,name,status, --output format='{{.PublicNet.IPv4.IP}}'.
Workflows where order matters
Single commands are well-covered by --help. The chains worth pinning down:
Server with SSH key + firewall, ready to log in — key and firewall must exist before server create references them:
hcloud ssh-key create --name <key> --public-key-from-file ~/.ssh/id_ed25519.pub
hcloud firewall create --name <fw> --rules-file rules.json
hcloud server create --name <srv> --type <type> --image ubuntu-24.04 \
--location hel1 --ssh-key <key> --firewall <fw>
hcloud server ssh <srv>
Replace firewall rules atomically (don't drift via repeated add-rule):
hcloud firewall replace-rules --rules-file rules.json <fw>
Gotchas
Public IPs get recycled. A new server may inherit a previously-used IP and SSH refuses with REMOTE HOST IDENTIFICATION HAS CHANGED!. After deleting a server, ssh-keygen -R <ip> and let ssh-keyscan re-add the new host key.
Context vs HCLOUD_TOKEN. Context (in user-config cli.toml) persists across shells — preferred for interactive work. Env var is preferred for non-interactive use, paired with --token-from-env. A token sitting in a .env file is not automatically exported — shells must source it.
Volumes are location-pinned. A volume in fsn1 cannot attach to a server in hel1. Match --location at creation.
hcloud zone is only half of DNS. The registrar's NS records must point to Hetzner's nameservers before queries resolve. Without that, the zone is just an internal database.
Match location to where users are; pretraining defaults to fsn1. Run hcloud location list and pick the closest. Private networks can't span network zones, only locations within one: eu-central (fsn1/hel1/nbg1), us-east (ash), us-west (hil), ap-southeast (sin).
Don't quote prices or server-type specs from memory. Always verify with hcloud server-type list before committing — names, specs, and pricing shift.
Deletion is immediate and unrecoverable. No undo on server delete or volume delete. describe first; create a snapshot (hcloud server create-image --type snapshot <srv>) beforehand if you might want the server back.
Hetzner Cloud ≠ Hetzner Robot. If the user mentions dedicated servers, server auctions, or the Robot dashboard — that's the other product. Surface the distinction; don't try to manage it here.
status: running is not reachability — check blocked. Hetzner null-routes a server's IPs at the network level for abuse reports or unpaid invoices. The server keeps reporting running and locked: false while nothing reaches it: not SSH, not the app, not ICMP.
hcloud server describe <srv> -o json | jq '.public_net | {v4:.ipv4.blocked, v6:.ipv6.blocked}'
blocked: true cannot be cleared from the API or the console — only Hetzner support lifts it. Do not debug firewalls, pg_hba, or application timeouts until you have ruled this out; the symptom is an indistinguishable ETIMEDOUT. Two tells that point here rather than at an allowlist: a port that is open to 0.0.0.0/0 (usually SSH/22) times out at the same moment as the application port, and every server on the account is blocked at once — that means an account-level action (billing or abuse), not a per-server fault.
replace-rules needs source_ips as a real JSON array. The file must match the API schema exactly, and hcloud rejects the whole file — leaving the old rules silently in place — if one field is shaped wrong:
json: cannot unmarshal object into Go struct field FirewallRule.source_ips of type []string
In PowerShell, build source_ips as an array (for example @('10.0.0.0/8', '192.168.0.0/16')) and pass enough ConvertTo-Json -Depth for the full rule structure. Since the write is all-or-nothing, always read the result back rather than assuming it applied:
hcloud firewall describe <fw> -o json | jq '.rules[] | {port, n: (.source_ips|length)}'
Docs
1---2name: hetzner-cloud3description: Manage Hetzner Cloud infrastructure with the `hcloud` CLI — servers, networks, firewalls, load balancers, volumes, DNS zones, SSH keys, primary/floating IPs, snapshots, certificates, placement groups, storage boxes. Use whenever the user mentions Hetzner, hcloud, VPS provisioning, or Hetzner location codes (fsn1, hel1, nbg1, ash, hil, sin) — even if they don't say "hcloud". CLI-only; does NOT cover Hetzner Robot (dedicated servers, separate product and API).4---56# Hetzner Cloud78Operate Hetzner Cloud through the `hcloud` CLI. When in doubt about server types, prices, locations, images, or flag syntax, run the discovery command rather than rely on this file or pretraining — the CLI is current.910## Authenticate1112Generate a token in Hetzner Console → project → Security → API Tokens, then either:1314```bash15hcloud context create <name> # interactive: stored in cli.toml, persists across shells16export HCLOUD_TOKEN="…" # CI/scripts: most commands read this automatically17```1819`hcloud context create` is the one common case that still prompts even with the env var set — pass `--token-from-env` to skip the prompt in non-interactive sessions.2021Health check: `hcloud datacenter list`.2223## Mental model2425`hcloud` manages everything inside **Hetzner Cloud**: servers, networks, firewalls, load balancers, volumes, DNS zones, SSH keys, primary/floating IPs, snapshots, certificates, placement groups, storage boxes.2627It does **not** manage:28- **Hetzner Robot** — dedicated/auction servers, separate product and API.29- Project creation, billing, team membership, API token issuing — web console only.3031**Discovery beats memorization.** Pretraining ages; the CLI is current.3233| Question | Command |34|---|---|35| Server types and prices | `hcloud server-type list` |36| Locations and datacenters | `hcloud location list` |37| OS images | `hcloud image list --type system` (add `--architecture arm` for ARM) |38| Command/flag details | `hcloud <resource> <verb> --help` |39| Everything in this project at a glance | `hcloud all list` |40| Is a server actually reachable? | `hcloud server describe <srv> -o json` → `public_net.ipv4.blocked` (see gotcha 9) |4142Structured output for scripts: `--output json | jq …`, `--output columns=id,name,status`, `--output format='{{.PublicNet.IPv4.IP}}'`.4344## Workflows where order matters4546Single commands are well-covered by `--help`. The chains worth pinning down:4748**Server with SSH key + firewall, ready to log in** — key and firewall must exist before `server create` references them:4950```bash51hcloud ssh-key create --name <key> --public-key-from-file ~/.ssh/id_ed25519.pub52hcloud firewall create --name <fw> --rules-file rules.json53hcloud server create --name <srv> --type <type> --image ubuntu-24.04 \54 --location hel1 --ssh-key <key> --firewall <fw>55hcloud server ssh <srv>56```5758**Replace firewall rules atomically** (don't drift via repeated `add-rule`):5960```bash61hcloud firewall replace-rules --rules-file rules.json <fw>62```6364## Gotchas65661. **Public IPs get recycled.** A new server may inherit a previously-used IP and SSH refuses with `REMOTE HOST IDENTIFICATION HAS CHANGED!`. After deleting a server, `ssh-keygen -R <ip>` and let `ssh-keyscan` re-add the new host key.67682. **Context vs `HCLOUD_TOKEN`.** Context (in user-config `cli.toml`) persists across shells — preferred for interactive work. Env var is preferred for non-interactive use, paired with `--token-from-env`. A token sitting in a `.env` file is **not** automatically exported — shells must source it.69703. **Volumes are location-pinned.** A volume in `fsn1` cannot attach to a server in `hel1`. Match `--location` at creation.71724. **`hcloud zone` is only half of DNS.** The registrar's NS records must point to Hetzner's nameservers before queries resolve. Without that, the zone is just an internal database.73745. **Match location to where users are; pretraining defaults to `fsn1`.** Run `hcloud location list` and pick the closest. Private networks can't span network zones, only locations within one: `eu-central` (fsn1/hel1/nbg1), `us-east` (ash), `us-west` (hil), `ap-southeast` (sin).75766. **Don't quote prices or server-type specs from memory.** Always verify with `hcloud server-type list` before committing — names, specs, and pricing shift.77787. **Deletion is immediate and unrecoverable.** No undo on `server delete` or `volume delete`. `describe` first; create a snapshot (`hcloud server create-image --type snapshot <srv>`) beforehand if you might want the server back.79808. **Hetzner Cloud ≠ Hetzner Robot.** If the user mentions dedicated servers, server auctions, or the Robot dashboard — that's the other product. Surface the distinction; don't try to manage it here.81829. **`status: running` is not reachability — check `blocked`.** Hetzner null-routes a server's IPs at the network level for abuse reports or unpaid invoices. The server keeps reporting `running` and `locked: false` while nothing reaches it: not SSH, not the app, not ICMP.8384 ```bash85 hcloud server describe <srv> -o json | jq '.public_net | {v4:.ipv4.blocked, v6:.ipv6.blocked}'86 ```8788 `blocked: true` cannot be cleared from the API or the console — **only Hetzner support lifts it**. Do not debug firewalls, `pg_hba`, or application timeouts until you have ruled this out; the symptom is an indistinguishable `ETIMEDOUT`. Two tells that point here rather than at an allowlist: a port that is open to `0.0.0.0/0` (usually SSH/22) times out at the same moment as the application port, and **every server on the account** is blocked at once — that means an account-level action (billing or abuse), not a per-server fault.899010. **`replace-rules` needs `source_ips` as a real JSON array.** The file must match the API schema exactly, and hcloud rejects the *whole* file — leaving the old rules silently in place — if one field is shaped wrong:9192 ```93 json: cannot unmarshal object into Go struct field FirewallRule.source_ips of type []string94 ```9596 In PowerShell, build `source_ips` as an array (for example `@('10.0.0.0/8', '192.168.0.0/16')`) and pass enough `ConvertTo-Json -Depth` for the full rule structure. Since the write is all-or-nothing, always read the result back rather than assuming it applied:9798 ```bash99 hcloud firewall describe <fw> -o json | jq '.rules[] | {port, n: (.source_ips|length)}'100 ```101102## Docs103104- API reference (per-resource endpoints): https://docs.hetzner.cloud/reference/cloud105- Cloud product guide: https://docs.hetzner.com/cloud/106- CLI source and changelog: https://github.com/hetznercloud/cli