Self-Host OpenClaw on Hetzner VPS
Hetzner offers some of the best price-to-performance ratios in the VPS market, making it an excellent choice for running OpenClaw Gateway. This guide walks you through provisioning a Hetzner Cloud server, installing Docker, and running OpenClaw behind an SSH tunnel for secure access.
Quick path
If you have done this before, here is the condensed checklist:
- Create a CX22 (2 vCPU / 4 GB) Debian 12 or Ubuntu 24.04 server in Hetzner Cloud
- SSH in, run
curl -fsSL https://get.docker.com | sh - Create directories:
mkdir -p ~/.openclaw/workspace - Create
.envwith gateway token, bind, port, and keyring password - Write
docker-compose.ymlwith volume mounts and127.0.0.1binding - Run
docker compose up -d - From your local machine:
ssh -N -L 18789:127.0.0.1:18789 root@VPS_IP - Open
http://127.0.0.1:18789/in your browser
Prerequisites
- A Hetzner Cloud account (sign up at hetzner.com/cloud)
- An SSH key pair on your local machine
- Basic familiarity with the Linux command line
Step 1 — Provision a Hetzner Cloud Server
Log into the Hetzner Cloud Console and create a new project or select an existing one.
Click Add Server and configure:
- Location: Choose the datacenter closest to you (Falkenstein, Nuremberg, or Helsinki for EU; Ashburn or Hillsboro for US)
- Image: Debian 12 or Ubuntu 24.04 LTS
- Type: CX22 (2 vCPU, 4 GB RAM, 40 GB NVMe) — the recommended minimum
- SSH Key: Select your public key
- Firewall: Create a firewall that allows only port 22 (SSH) inbound
- Name: Something memorable like
openclaw-gateway
Click Create & Buy Now. The server will be ready in about 30 seconds.
Take note of the public IPv4 address.
Step 2 — Initial Server Setup
SSH into your new server:
Update the system packages:
Add swap space (recommended for smaller VMs)
If you are on a 2 GB RAM plan, or want extra safety on 4 GB, add swap:
Verify with free -h — you should see 2 GB of swap.
Step 3 — Install Docker
Install Docker using the official convenience script:
Verify the installation:
Both commands should return version numbers without errors.
Step 4 — Prepare OpenClaw Directories
Create the persistent directories that OpenClaw needs:
~/.openclawstores configuration, keys, and internal state~/.openclaw/workspaceis the working directory where OpenClaw reads and writes project files
Step 5 — Create the Environment File
Generate a secure keyring password and gateway token:
Now create the .env file:
Replace your_token_here and your_keyring_password_here with the values you generated above.
Set restrictive permissions:
Step 6 — Write the Docker Compose File
Create the compose file:
Key details in this configuration:
127.0.0.1:18789:18789binds the port to loopback only. The gateway is never exposed to the public internet.- Volume mounts ensure your configuration and workspace data persist across container restarts and upgrades.
no-new-privilegesandread_onlyadd defense-in-depth.
Step 7 — Start OpenClaw
Check that the container is running:
You should see the gateway reporting that it is listening on port 18789.
Step 8 — Connect via SSH Tunnel
On your local machine (not the server), open a terminal and run:
This forwards your local port 18789 to the server's loopback port 18789. The -N flag tells SSH not to open a remote shell.
Leave this terminal running. In your browser, navigate to:
You should see the OpenClaw Gateway interface. Enter your OPENCLAW_GATEWAY_TOKEN when prompted.
Persistent SSH tunnel with autossh
For a more resilient connection, install autossh:
Security Best Practices
Trust boundaries
OpenClaw Gateway executes code on your server. Treat the trust boundary seriously:
- Never expose port 18789 to the public internet. Always use SSH tunnels, Tailscale, or WireGuard.
- Use a dedicated server for OpenClaw rather than sharing it with production workloads.
- Keep the gateway token secret. Anyone with the token and network access can execute arbitrary code.
- Enable automatic security updates:
Firewall
Hetzner Cloud Firewall should already restrict inbound traffic to SSH. As a belt-and-suspenders measure, also configure the host firewall:
SSH hardening
Disable password authentication if you have not already:
Infrastructure as Code with Terraform
If you prefer to automate your Hetzner setup, the Hetzner Cloud Terraform provider makes this straightforward:
After terraform apply, use the provisioner or a tool like Ansible to run the Docker setup steps from this guide.
Updating OpenClaw
To pull the latest gateway image:
Your configuration and workspace data are stored on the host filesystem and will not be affected.
Troubleshooting
Container exits immediately
Check the logs:
Common causes: missing or malformed .env file, incorrect file permissions, or insufficient disk space.
Out of memory (OOM) kills
If dmesg | grep -i oom shows kills, either upgrade to a larger instance or add more swap. The CX22 with 4 GB RAM and 2 GB swap handles most workloads comfortably.
SSH tunnel drops
Use autossh as described above, or add ServerAliveInterval 60 and ServerAliveCountMax 3 to your ~/.ssh/config for the host.
Cannot connect to gateway
Verify the container is running (docker compose ps), check that the port binding shows 127.0.0.1:18789 (not 0.0.0.0:18789), and confirm your SSH tunnel is active.
DNS resolution fails inside container
If the container cannot resolve external hostnames, check /etc/resolv.conf on the host or add explicit DNS to the compose file:
Next Steps
- Set up a Tailscale mesh network for zero-config secure access without SSH tunnels
- Configure automated backups of
~/.openclawusing Hetzner's snapshot feature or a cron job withrestic - Explore multi-user access by running multiple gateway instances on different ports behind separate tokens