Self-Host OpenClaw on Any Linux Server
This guide covers installing OpenClaw Gateway on any Ubuntu or Debian-based Linux server, whether it is a bare-metal machine, a VPS from any provider, or a homelab box under your desk. Two installation paths are documented: a direct install using the official installer script, and a Docker-based setup for those who prefer container isolation.
Quick path
Direct install in five commands:
curl -fsSL https://openclaw.ai/install.sh | bashopenclaw doctor(verify environment)openclaw setup(configure gateway token, bind, port)- Copy the systemd unit below, run
systemctl enable --now openclaw-gateway - SSH tunnel from your machine:
ssh -N -L 18789:127.0.0.1:18789 user@SERVER_IP
Prerequisites
- Ubuntu 22.04+ or Debian 11+ (other distributions may work but are untested)
- At least 2 GB RAM (1 GB with swap as a minimum)
- 10 GB free disk space
- SSH access to the server
- A non-root user with sudo privileges (or root access)
Path A — Direct Install (Recommended)
The direct install is the fastest way to get OpenClaw running. It installs Node.js if needed, downloads the OpenClaw binary, and sets up the configuration directory.
Step 1 — Run the installer
The script will:
- Detect your OS and architecture
- Install Node.js 24 if not present or if the installed version is too old
- Download and install the OpenClaw Gateway binary to
/usr/local/bin/ - Create the configuration directory at
~/.openclaw - Create the workspace directory at
~/.openclaw/workspace
Step 2 — Verify the installation
This should print the installed version. If you get command not found, see the Troubleshooting section below.
Run the environment checker:
The doctor command validates:
- Node.js version (24+ required)
- Available memory and swap
- Disk space
- Network connectivity
- Write permissions on the configuration directory
Fix any issues it reports before proceeding.
Step 3 — Configure the gateway
Run the interactive setup wizard:
You will be prompted for:
- Gateway token: A secret used to authenticate clients. Let the wizard generate one, or provide your own (at least 32 characters).
- Bind address:
loopback(127.0.0.1, most secure) orlan(all interfaces, useful for Tailscale). - Port: Default
18789. - Workspace path: Default
~/.openclaw/workspace.
The configuration is saved to ~/.openclaw/config.toml:
You can edit this file directly at any time. Restart the service after changes.
Step 4 — Test the gateway
Start the gateway manually to confirm everything works:
You should see output indicating the gateway is listening. Press Ctrl+C to stop it once confirmed.
Step 5 — Create a systemd service
Set up systemd so the gateway runs on boot and restarts on failure:
Replace youruser with your actual username.
Enable and start:
Verify:
Path B — Docker Install
If you prefer containerized deployments, this path uses Docker Compose.
Step 1 — Install Docker
Log out and back in for the group change to take effect.
Step 2 — Create directory structure
Step 3 — Create the environment file
Generate secure values for the token and keyring password:
Step 4 — Write the Docker Compose file
Step 5 — Start the container
Connecting to the Gateway
SSH tunnel
On your local machine, forward the gateway port through SSH:
Then open http://127.0.0.1:18789/ in your browser.
Add this to your local ~/.ssh/config for convenience:
Then just run ssh -N openclaw-server.
Tailscale (alternative)
If your server is on a Tailscale network, you can access OpenClaw without SSH tunnels:
Access via https://SERVER_TAILSCALE_NAME:443/ from any device on your tailnet.
Firewall Configuration
Using ufw (Ubuntu/Debian)
Do not open port 18789 in the firewall. Access is through SSH tunnel or VPN only.
Using iptables directly
If you prefer raw iptables:
Security Best Practices
Keep OpenClaw off the public internet
OpenClaw Gateway executes code on your server. Never bind it to 0.0.0.0 without a VPN or tunnel in front. The 127.0.0.1 binding in the Docker Compose file and the loopback setting in config.toml enforce this.
Automatic security updates
SSH hardening
Disable password authentication:
Run as a dedicated user
Avoid running OpenClaw as root. Create a dedicated system user:
Update the systemd unit or Docker user mapping accordingly.
Swap Setup for Low-Memory Servers
If your server has 1-2 GB of RAM, add swap to prevent OOM kills:
Verify with free -h.
Troubleshooting
openclaw: command not found
The installer places the binary in /usr/local/bin/. If this is not in your PATH:
If running under systemd, ensure the ExecStart uses the full path (/usr/local/bin/openclaw).
npm sharp build errors
The sharp image processing library requires native dependencies. If you see build errors during installation:
Then re-run the installer:
Node.js version too old
The installer should handle this, but if you have a system-managed Node.js that takes precedence:
Gateway fails to start — EADDRINUSE
Port 18789 is already in use:
Either stop the conflicting process or change the port in config.toml / .env.
Systemd service keeps restarting
Check the logs for the root cause:
Common causes:
- Missing or corrupt
config.toml - Insufficient memory (check
dmesg | grep -i oom) - Wrong file permissions — the service user must own
~/.openclaw
Docker container exits immediately
Common causes:
- Missing
.envfile or wrong path inenv_file - Volume mount permissions — ensure the host directories exist and are writable
- Insufficient disk space — check with
df -h
Connection refused on localhost
- Confirm the service is running:
systemctl is-active openclaw-gatewayordocker compose ps - Confirm the port is listening:
ss -tln | grep 18789 - Confirm you are connecting to
127.0.0.1, not the server's public IP - If using SSH tunnel, verify the tunnel is active with
ssh -v
Updating OpenClaw
Direct install
Docker
Your configuration and workspace data are preserved in both cases, since they live on the host filesystem.
Next Steps
- Set up automated backups of
~/.openclawusingrestic,borgbackup, or provider-specific snapshots - Configure log rotation for systemd journal output:
sudo journalctl --vacuum-size=500M - Explore running multiple OpenClaw instances for different projects on separate ports
- Add monitoring with a lightweight tool like Netdata or Prometheus Node Exporter