Get the FREE Ultimate OpenClaw Setup Guide →

hcloud-setup

Scanned
npx machina-cli add skill danjdewhurst/hcloud-skills/hcloud-setup --openclaw
Files (1)
SKILL.md
9.0 KB

hcloud CLI Setup and Configuration

Installation

Manual (GitHub Releases)

Download pre-built binaries from GitHub releases. Extract and move the binary to a directory in your PATH.

Example for 64-bit Linux:

curl -sSLO https://github.com/hetznercloud/cli/releases/latest/download/hcloud-linux-amd64.tar.gz
sudo tar -C /usr/local/bin --no-same-owner -xzf hcloud-linux-amd64.tar.gz hcloud
rm hcloud-linux-amd64.tar.gz

Go

go install github.com/hetznercloud/cli/cmd/hcloud@latest

Note: Binaries built with Go will not have the correct version embedded.

Homebrew (Linux / macOS)

brew install hcloud

Windows

WinGet:

winget install HetznerCloud.CLI

Scoop:

scoop install hcloud

Note: The WinGet and Scoop package entries are not maintained by Hetzner.

Docker

docker run --rm -e HCLOUD_TOKEN="<token>" hetznercloud/cli:latest <command>

To persist configuration, mount the config file:

docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest <command>

Interactive shell:

docker run -it --rm --entrypoint /bin/sh hetznercloud/cli:latest

Debian-based distributions (using apt) provide outdated versions of the hcloud CLI. Use one of the other installation methods instead.

Shell Completion

Bash

Load into current shell:

source <(hcloud completion bash)

Make permanent by adding the line above to ~/.bashrc.

Zsh

Generate the completion file:

mkdir -p ~/.config/hcloud/completion/zsh
hcloud completion zsh > ~/.config/hcloud/completion/zsh/_hcloud

Add to ~/.zshrc (the fpath line must come before compinit):

fpath+=(~/.config/hcloud/completion/zsh)
# ... anything else that needs to be done before compinit
autoload -Uz compinit; compinit

Restart the shell for changes to take effect.

Fish

Permanent installation:

hcloud completion fish > ~/.config/fish/completions/hcloud.fish

Load into current shell only:

hcloud completion fish | source

PowerShell

Save completion script:

hcloud completion powershell > hcloud.ps1

Load into current shell:

hcloud completion powershell | Out-String | Invoke-Expression

Source the saved file from your PowerShell profile for persistence.

Context Management

Contexts manage multiple Hetzner Cloud API tokens and per-project configuration.

Create a context

hcloud context create <name>

Prompts interactively for an API token. To use the HCLOUD_TOKEN environment variable instead:

hcloud context create --token-from-env <name>
FlagDescription
--token-from-envUse HCLOUD_TOKEN from environment without prompting

Switch context

hcloud context use <context>

Show active context

hcloud context active

List all contexts

hcloud context list [options]
FlagDescription
-o, --output stringArrayOutput options: noheader|columns=...

Available columns: active, name.

Delete a context

hcloud context delete <context>

Rename a context

hcloud context rename <context> <name>

Unset active context

hcloud context unset

Config Management

Configuration file location: ~/.config/hcloud/cli.toml

Config hierarchy (highest to lowest priority)

  1. Flags
  2. Environment variables
  3. Configuration file (context)
  4. Configuration file (global)
  5. Default values

Set a value

hcloud config set <key> <value>...
FlagDescription
--globalSet the value globally (for all contexts)

Get a value

hcloud config get <key>
FlagDescription
--allow-sensitiveAllow showing sensitive values
--globalGet the value globally

List configuration

hcloud config list
FlagDescription
-a, --allAlso show default values
--allow-sensitiveAllow showing sensitive values
-g, --globalOnly show global values
-o, --output stringArrayOutput options: noheader|columns=...|json|yaml

Add values to a list

hcloud config add <key> <value>...
FlagDescription
--globalSet the value globally (for all contexts)

Remove values from a list

hcloud config remove <key> <value>...
FlagDescription
--globalRemove the value(s) globally (for all contexts)

Unset a value

hcloud config unset <key>
FlagDescription
--globalUnset the value globally (for all contexts)

Preference keys

These keys can be used with set, unset, add, and remove:

KeyDescriptionTypeConfig keyEnv variable
debugEnable debug outputbooleandebugHCLOUD_DEBUG
debug-fileFile to write debug output tostringdebug_fileHCLOUD_DEBUG_FILE
default-ssh-keysDefault SSH Keys for new Servers and Storage Boxesstring listdefault_ssh_keysHCLOUD_DEFAULT_SSH_KEYS
endpointHetzner Cloud API endpointstringendpointHCLOUD_ENDPOINT
hetzner-endpointHetzner API endpointstringhetzner_endpointHETZNER_ENDPOINT
no-experimental-warningsSuppress experimental warningsbooleanno_experimental_warningsHCLOUD_NO_EXPERIMENTAL_WARNINGS
poll-intervalPolling interval for action progressdurationpoll_intervalHCLOUD_POLL_INTERVAL
quietOnly print error messagesbooleanquietHCLOUD_QUIET
sort.<resource>Default sorting for a resourcestring listsort.<resource>HCLOUD_SORT_<RESOURCE>

Non-preference keys (read-only via config)

KeyDescriptionTypeConfig keyEnv variable
configConfig file pathstringHCLOUD_CONFIG
contextCurrently active contextstringactive_contextHCLOUD_CONTEXT
tokenHetzner Cloud API tokenstringtokenHCLOUD_TOKEN

These cannot be modified with hcloud config set or hcloud config unset, but can be retrieved with hcloud config get and hcloud config list.

Global Flags

These flags are inherited by all commands:

FlagDescriptionDefault
--config stringConfig file path~/.config/hcloud/cli.toml
--context stringCurrently active context
--debugEnable debug output
--debug-file stringFile to write debug output to
--endpoint stringHetzner Cloud API endpointhttps://api.hetzner.cloud/v1
--hetzner-endpoint stringHetzner API endpointhttps://api.hetzner.com/v1
--no-experimental-warningsSuppress experimental warnings
--poll-interval durationPolling interval for action progress500ms
--quietOnly print error messages

Output Formatting

JSON output

Supported by describe, list, and create commands. Lists return an array, describe returns an object.

hcloud server list --output json
hcloud server describe my-server --output json

Use with jq for filtering:

hcloud server list -o json | jq '.[] | .name'

YAML output

Supported by describe, list, and create commands.

hcloud server list --output yaml

Use with yq for filtering:

hcloud server list --output yaml | yq '.[] | .name'

Go template format (describe only)

hcloud server describe my-server --output format='{{.ServerType.Cores}}'

Table options (list only)

Remove the table header:

hcloud server list --output noheader

Select specific columns:

hcloud server list --output columns=id,name

Combine options:

hcloud server list --output noheader --output columns=id,name

Use --help on any list command to see all available columns.

Other Commands

Print version

hcloud version

List all resources

hcloud all list [options]

Lists all resources in the project (Servers, Images, Placement Groups, Primary IPs, ISOs, Volumes, Load Balancers, Floating IPs, Networks, Firewalls, Certificates, SSH Keys, Storage Boxes, Zones). Does not include static/public resources like Locations or public ISOs.

FlagDescription
--paidOnly list resources that cost money
-l, --selector stringSelector to filter by labels
-o, --output stringArrayOutput options: json|yaml

Source

git clone https://github.com/danjdewhurst/hcloud-skills/blob/main/skills/hcloud-setup/SKILL.mdView on GitHub

Overview

The hcloud-setup skill covers installing the Hetzner Cloud CLI (hcloud), configuring defaults, and managing contexts and tokens. It also guides enabling shell completion and locating or editing the CLI config file to persist settings across sessions.

How This Skill Works

Install the hcloud CLI via binaries, Go, Homebrew, Windows package managers, or Docker. Create and switch contexts to manage multiple API tokens, including options to use tokens from the environment. The CLI reads configuration from flags, environment variables, and config files (with a defined hierarchy) and supports shell completion for Bash, Zsh, Fish, and PowerShell.

When to Use It

  • You need to install the hcloud CLI on Linux, macOS, or Windows using the preferred method (manual binary, Go, Homebrew, WinGet, or Scoop, or Docker).
  • You want to enable and configure shell completion for Bash, Zsh, Fish, or PowerShell to speed up commands.
  • You work with multiple Hetzner Cloud projects and manage tokens with separate contexts for each project.
  • You need to locate or edit the CLI config file at ~/.config/hcloud/cli.toml and understand the priority of config sources.
  • You want to run commands using a token from the HCLOUD_TOKEN environment variable instead of interactive prompts.

Quick Start

  1. Step 1: Install the hcloud CLI using your preferred method (e.g., brew install hcloud or go install github.com/hetznercloud/cli/cmd/hcloud@latest).
  2. Step 2: Create or switch a context; you can use a token interactively or via --token-from-env: hcloud context create my-context or hcloud context create --token-from-env my-context.
  3. Step 3: Enable shell completion and verify: hcloud completion bash > ~/.config/hcloud/completion/bash/_hcloud; source ~/.bashrc; hcloud context active.

Best Practices

  • Choose the installation method best suited to your OS; Debian-based apt can be outdated—prefer manual binaries, Go, Homebrew, or Docker.
  • Use hcloud context create with --token-from-env to securely source tokens from your environment variable HCLOUD_TOKEN.
  • When using Docker, persist configuration by mounting ~/.config/hcloud/cli.toml into the container.
  • Enable shell completion for your shell to reduce typos and improve command discovery.
  • Leverage the output formatting options (-o/--output) to tailor displayed data for scripts and dashboards.

Example Use Cases

  • Install hcloud on macOS with Homebrew: brew install hcloud; verify with hcloud version.
  • Create a new context and enter the API token when prompted: hcloud context create my-prod.
  • Create a context from env token: hcloud context create --token-from-env my-prod.
  • Generate and load Bash completion: source <(hcloud completion bash); add to .bashrc to persist.
  • Run hcloud in Docker and persist config: docker run --rm -v ~/.config/hcloud/cli.toml:/config.toml hetznercloud/cli:latest <command>.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers