Skip to content

Deploying OpenClaw on a small IaaS VPS for 24/7 access

Run the OpenClaw personal AI agent on a small Ubuntu 24.04 VPS — Node 24, systemd unit, gateway on loopback, Tailscale or Cloudflare Tunnel for remote access. 24/7 access from any device.

You have OpenClaw running on the laptop and it is genuinely useful. It checks your inbox, runs the morning briefing, kicks off the gym playlist when you open the door. The catch is obvious — close the lid, the agent stops. You want it always on, reachable from a phone on cellular, from the laptop when you are travelling, from the iPad on the kitchen counter. The right answer is a small IaaS VPS the agent calls home, not your laptop pretending to be one.

OpenClaw is a Node.js daemon with a gateway listening on TCP 18789 (github.com/openclaw/openclaw). It is small. A 2 vCPU / 2 GB VPS handles a single power user with room to spare, as long as the local-model option is off the table — language-model inference is delegated to the upstream provider, so the VPS does message routing, skill execution, browser automation, and memory I/O, not weight crunching (openclaw.ai). This article walks the build for that 2 vCPU / 2 GB box, from a fresh Ubuntu 24.04 install to a daemon you can hit from your phone via Tailscale or Cloudflare Tunnel.

What’s happening

A small always-on OpenClaw VPS has four things that have to be right and a lot of things that do not matter.

The four that matter:

  1. The daemon does not run as root or as your interactive user. A dedicated openclaw system user owns the workspace and runs the gateway. If a skill goes wrong, the blast radius stops at the workspace.
  2. The gateway binds on 127.0.0.1:18789, not 0.0.0.0. The default port is 18789 (github.com/openclaw/openclaw). Anyone who finds the public IP must not find the gateway. Remote access goes through Tailscale or a Cloudflare Tunnel that authenticates first and reverse-proxies second.
  3. The workspace lives under /var/lib/openclaw/ on a path the backup picks up. OpenClaw’s workspace root is ~/.openclaw/workspace by default with skills under ~/.openclaw/workspace/skills/ and config at ~/.openclaw/openclaw.json (github.com/openclaw/openclaw). The HOME= override on the unit puts those under /var/lib/openclaw so they end up on a directory you actually back up.
  4. Provider keys live in /etc/openclaw/openclaw.env with mode 0640, root-owned, openclaw-readable. They never appear in shell history, never sit in the project’s working directory, never get committed to a repo.

Everything else — distro choice, swap, journald retention, whether the VPS panel calls it a “droplet” or an “instance” — is preference.

Prerequisites

  • A small VPS with 2 vCPU and 2 GB RAM. Ubuntu 24.04 LTS is the default in this guide; Ubuntu 22.04 works with the same flow.
  • SSH key login, password login disabled.
  • An LLM provider key — Claude, GPT, or a local model reachable from the VPS (openclaw.ai — integrations).
  • A Tailscale account or a Cloudflare account, depending on which remote-access path you pick. Both work; pick one.
  • A DNS name only if you choose the Cloudflare Tunnel path. Tailscale uses MagicDNS and does not need one.

How to verify

By the time the build is done, the listening sockets on the public NIC must be exactly these:

ss -lntp
# 0.0.0.0:22         sshd
# 127.0.0.1:18789    node (openclaw gateway)

Specifically, port 18789 must not appear on 0.0.0.0. Confirm from a remote host:

nc -zv <vps-public-ip> 18789
# Connection refused — correct

The gateway responds locally:

ssh openclaw-vps "curl -fsS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:18789/health"
# 200 (or 401, depending on auth — but not a connection error)

And openclaw doctor should be green:

ssh openclaw-vps "sudo -u openclaw HOME=/var/lib/openclaw /usr/bin/openclaw doctor"

If you pick Tailscale for remote access, tailscale status lists the VPS as an active node and a curl from any device on the tailnet hits the gateway through the tailnet IP, not the public IP.

The fix

Save the script below as /root/setup-openclaw-ubuntu24.sh. Run it as root on a fresh Ubuntu 24.04 VPS. It updates the base OS, hardens SSH, installs Node 24, creates the openclaw user, installs OpenClaw, writes the env file and systemd unit, and leaves you ready for the remote-access step.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 24.04 OpenClaw clean VPS installer
### Daemon runs as the openclaw user; gateway binds on 127.0.0.1:18789
### Provider keys live in /etc/openclaw/openclaw.env (root:openclaw 0640)
### Workspace on /var/lib/openclaw — back this directory up.

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${ANTHROPIC_API_KEY:?Set ANTHROPIC_API_KEY=sk-ant-... (or use OPENAI_API_KEY)}"

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install \
  curl ca-certificates gnupg build-essential \
  ufw fail2ban unattended-upgrades \
  chrony jq iproute2 lsof

systemctl enable --now chrony
timedatectl set-ntp true

echo "==> UFW: deny inbound except SSH"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw --force enable

echo "==> SSH hardening (keep root key login, drop passwords)"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*KbdInteractiveAuthentication.*|KbdInteractiveAuthentication no|' /etc/ssh/sshd_config
sshd -t
systemctl restart ssh

echo "==> fail2ban for sshd"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

echo "==> Unattended security upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Installing Node.js 24 from NodeSource"
curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
apt-get install -y nodejs
apt-mark hold nodejs

echo "==> Creating openclaw system user"
if ! id -u openclaw >/dev/null 2>&1; then
  useradd --system --home-dir /var/lib/openclaw --shell /usr/sbin/nologin openclaw
fi
mkdir -p /var/lib/openclaw
chown -R openclaw:openclaw /var/lib/openclaw
chmod 750 /var/lib/openclaw

echo "==> Installing OpenClaw globally"
npm install -g openclaw@latest

echo "==> Writing /etc/openclaw/openclaw.env"
install -d -m 0750 -o openclaw -g openclaw /etc/openclaw
cat > /etc/openclaw/openclaw.env <<ENV
ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
OPENCLAW_HOME=/var/lib/openclaw
OPENCLAW_GATEWAY_BIND=127.0.0.1
OPENCLAW_GATEWAY_PORT=18789
ENV
chown root:openclaw /etc/openclaw/openclaw.env
chmod 0640 /etc/openclaw/openclaw.env

echo "==> Writing systemd unit"
cat > /etc/systemd/system/openclaw-gateway.service <<'UNIT'
[Unit]
Description=OpenClaw gateway daemon
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=openclaw
Group=openclaw
WorkingDirectory=/var/lib/openclaw
EnvironmentFile=/etc/openclaw/openclaw.env
ExecStart=/usr/bin/openclaw gateway --port 18789
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/var/lib/openclaw
ProtectHome=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictNamespaces=true
LockPersonality=true
SystemCallArchitectures=native

LimitNOFILE=65536
MemoryMax=1500M

[Install]
WantedBy=multi-user.target
UNIT

systemctl daemon-reload

echo "==> First-run onboarding"
sudo -u openclaw HOME=/var/lib/openclaw /usr/bin/openclaw onboard || {
  echo "Onboarding requires interactive input. Re-run:"
  echo "  sudo -u openclaw HOME=/var/lib/openclaw /usr/bin/openclaw onboard"
}

echo "==> Enabling gateway"
systemctl enable --now openclaw-gateway.service

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
ss -lntp | grep -E ':(22|18789)\b' || true
echo
echo "Gateway is on 127.0.0.1:18789. To reach it from another device, add Tailscale or a Cloudflare Tunnel — see the linked KBs."

Run it:

chmod 700 /root/setup-openclaw-ubuntu24.sh
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
  /root/setup-openclaw-ubuntu24.sh

Onboarding runs as the openclaw user with the HOME=/var/lib/openclaw override so the workspace ends up under /var/lib/openclaw/.openclaw/ (github.com/openclaw/openclaw — configuration). If onboarding bombs because of an interactive prompt your shell could not satisfy (a common case on the first run from a managed terminal), re-run the openclaw onboard line by hand before starting the unit.

Step two: remote access

The gateway is now alive on 127.0.0.1:18789 and not reachable from anywhere except the VPS itself. Pick one.

curl -fsSL https://tailscale.com/install.sh | sh
tailscale up --hostname=openclaw-vps --ssh
tailscale status

The VPS shows up in your tailnet with a 100.x.y.z address. From any other tailnet device — phone, laptop, iPad — hit http://openclaw-vps:18789/health and the daemon answers. No public ingress was ever opened. Tailscale handles the encrypted overlay, ACL, and key rotation. For the full architecture write-up, see Private-network architecture for an OpenClaw deployment.

Cloudflare Tunnel (when you want a public hostname)

The VPS dials out to Cloudflare; nothing inbound is opened. The hostname claw.example.com resolves to a Cloudflare edge IP, the tunnel authenticates with Cloudflare Access, and the request reaches the gateway over the tunnel (developers.cloudflare.com — Cloudflare Tunnel):

curl -fsSL https://pkg.cloudflare.com/cloudflared-keyring.gpg \
  | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" \
  | sudo tee /etc/apt/sources.list.d/cloudflared.list

sudo apt-get update
sudo apt-get install -y cloudflared

cloudflared tunnel login
cloudflared tunnel create openclaw
cloudflared tunnel route dns openclaw claw.example.com

Then write /etc/cloudflared/config.yml:

tunnel: openclaw
credentials-file: /etc/cloudflared/openclaw.json
ingress:
  - hostname: claw.example.com
    service: http://127.0.0.1:18789
  - service: http_status:404

And run it as a service:

sudo cloudflared service install
sudo systemctl enable --now cloudflared

Wire Cloudflare Access in front of the hostname so the tunnel does not just answer to anyone with the URL. That step plus a Caddy reverse-proxy alternative is covered in DNS, TLS, and secure remote access to OpenClaw.

What an always-on personal agent actually costs

There is no dollar figure here on purpose — relative sizing is the useful thing. A single-user OpenClaw VPS is dominated by three drivers:

  1. LLM API calls. The model provider does the heavy lifting. A busy day with browser automation and several long chats can spike spend; a quiet day costs almost nothing. Cache where the model supports it.
  2. Concurrent skills. Each background skill — cron jobs, watchers, integrations — adds idle Node memory. A dozen integrations is normal, a hundred is not personal use.
  3. Memory volume. Persistent memory grows linearly with use; weeks-long retention is the difference between a couple hundred MB and a couple GB.

The compute envelope — the VPS itself — is small and flat. The variable line is the upstream LLM. For the full sizing framework see IaaS cost model for an always-on OpenClaw.

Operating it after day one

A handful of habits keeps the box healthy:

  • Subscribe to journalctl -u openclaw-gateway.service -f for the first week. Watch for skill errors, OAuth refresh failures, browser-control crashes. They are loud in the logs.
  • Run openclaw doctor weekly. It catches drift — a stale workspace permission, a missing dependency after a Node hold expired.
  • Pin Node. Major Node upgrades during unattended updates would kill the daemon mid-week. apt-mark hold nodejs is the cheap insurance the script applied.

Run the production OpenClaw on a Stack Harbor-managed environment with patch cadence, monitoring, and Sev-1 escalation built in: Managed Cloud Ops — or scope an AI deployment with us if you want this taken off your plate.

Last verified on OpenClaw current.