OpenClaw 如何在 VPS 上自託管運行:AI 助手逐步教學
How to Run OpenClaw on a VPS (Self-Hosted AI Assistant, Step by Step)
這份指南逐步説明如何在 VPS 上部署 OpenClaw 自託管 AI 助手,並設定服務以維持 24/7 運行。指南建議使用 2 GB RAM、1-2 vCPU 的 VPS,並以 SSH-only 防火牆及帶驗證的反向代理保護遠端 Control UI。OpenClaw 可使用 Claude、GPT、Gemini 或 Ollama 作為模型,並連接 Telegram、WhatsApp 等聊天平台。
How to Run OpenClaw on a VPS (Self-Hosted AI Assistant, Step by Step)
OpenClaw is the open-source, self-hosted AI assistant that hit 380k+ GitHub stars in 2026 — it turns your machine (or a server) into a personal assistant you can message from WhatsApp, Telegram, Slack, Discord, and 20+ other apps, powered by whatever model you want, with all data staying on your hardware.
The one question everyone asks: where do I actually run it so it's always on? Not your laptop — that goes to sleep. The answer is a small, cheap VPS. This is the exact setup I use, written so you can replicate it in about an hour.
Why a VPS (and not your laptop)
A personal assistant is only useful if it's there 24/7. Your laptop sleeps, reboots, and takes your Wi-Fi with it. A VPS:
- Stays on 24/7 regardless of your devices
- Gives OpenClaw its own persistent home (config, memory, sessions)
- Can sit in a datacenter close to your AI model provider
All you need is roughly 2 GB RAM and a couple of vCPUs — OpenClaw itself is light; your AI provider does the heavy lifting. That's a low-cost VPS tier, which is the whole point.
Step 1 — Get the hardware
Pick a small VPS. For a personal OpenClaw setup, a single 2 GB / 1-2 vCPU instance is plenty:
- What to grab: 1 vCPU, 2 GB RAM, 20+ GB SSD, an NVMe volume, and an IPv4 address.
- Where: any provider with a low entry tier works. I run mine on Hostinger's VPS — their launch VPS plans start around $5-6/mo, which is the cheapest honest price for a machine that never sleeps.
- OS: I use a plain Linux image (Ubuntu 22.04/24.04 or Debian 12). Skip "managed" stacks for the base — you'll be installing Node anyway.
After provisioning you get a root/SSH login. That's all you need for this step.
Step 2 — Open the right port and lock the firewall
OpenClaw's Gateway listens on a local port. You only ever connect through SSH, so keep the default SSH-only exposure:
- In your provider's control panel, open one port for SSH (22).
- Do not open OpenClaw's port to the public internet. Run it behind an authenticated reverse proxy (see Step 5) instead.
Then on the box, install ufw and lock it down:
sudo apt update && sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw enable
Step 3 — Install Node and OpenClaw
OpenClaw is built on Node. Install a current LTS Node, then OpenClaw:
# Node LTS (via NodeSource)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install -y nodejs
# OpenClaw (follows its documented install)
curl -fsSL https://openclaw.ai/install.sh | bash
Confirm the version, then start the setup wizard:
openclaw --version
openclaw setup
The setup wizard walks you through: model provider, API key, the channels you want (Telegram / WhatsApp / etc.), and where OpenClaw keeps its workspace (its config, memory, and operating instructions). Let it use the default ~/.openclaw workspace on the VPS.
Step 4 — Connect your AI model (bring your own key)
OpenClaw is model-agnostic — Claude, GPT, Gemini, or fully local via Ollama. For a 24/7 personal assistant I recommend a hosted model provider (reliable, no GPU cost on the VPS):
- Get an API key from your chosen provider.
- Put it in OpenClaw's config / environment — never hardcode it in a file you'll commit.
- Test with a one-shot prompt to confirm the round-trip works.
Cost control: the VPS is a few dollars/month; your AI usage is the variable cost. Pick a model tier you'll actually use, and set provider spend limits so an agent that loops can't surprise you.
Step 5 — Keep it running 24/7 (systemd)
Don't just run it in a terminal that dies when you log out. Make OpenClaw a service:
# /etc/systemd/system/openclaw.service
[Unit]
Description=OpenClaw Gateway
After=network-online.target
Wants=network-online.target
[Service]
User=youruser
ExecStart=/usr/local/bin/openclaw gateway
Restart=always
RestartSec=5
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
Then:
sudo systemctl enable --now openclaw
sudo systemctl status openclaw
Restart=always means if it ever crashes, systemd brings it right back — the whole point of a 24/7 assistant.
Step 6 — Reach it from your phone (reverse proxy + auth)
The Gateway has a browser Control UI. To reach it from your phone over the internet safely:
- Put it behind Caddy or nginx with a free SSL cert.
- Front it with basic-auth or OAuth so the world can't open your assistant.
Caddy makes the TLS part automatic:
openclaw.example.com {
basic_auth {
youruser <hash> # run: caddy hash-password
}
reverse_proxy 127.0.0.1:<openclaw-port>
}
Point a cheap domain (or a subdomain of one you have) at the VPS's IP, and Caddy issues the cert. Now your phone reaches the assistant at https://openclaw.example.com — encrypted, and only you can in.
(A simpler alternative: SSH tunnel — ssh -L 8080:localhost:<port> your-vps and open localhost:8080 in your phone browser. Zero extra setup, no public exposure at all.)
Step 7 — Point your channels at it
Now the satisfying part. Connect the chat apps you already use:
- Telegram: create a bot via BotFather, drop the token into OpenClaw. Message the bot — that's your assistant.
- WhatsApp: link a dedicated number (the two-phone setup OpenClaw recommends: one number just for the assistant, so your personal chats stay private).
- Slack / Discord / Signal / iMessage: OpenClaw supports these through its channel plugins.
From that moment, your "assistant" lives on the VPS and is reachable from anywhere.
Keeping it healthy
-
Back up the workspace (
~/.openclaw) — that's the memory and config you can't get back. A nightlyrsyncor tarball to object storage is enough. - Watch disk: logs and sessions grow; add a small rotation.
- Update deliberately: OpenClaw moves fast, but test an update in a clone before rolling it onto the box your assistant runs on.
-
Credentials: keep API keys in env vars or a secrets file with
600perms, never in the repo.
The honest bottom line
The VPS itself is the cheapest part — a few dollars a month on a provider like Hostinger (referral code OVDAMRMASPIM). The real work is the setup: Node, systemd, a locked-down firewall, and a reverse proxy in front of the Control UI. Do it once and you have an always-on, model-flexible, private assistant that meets you in the apps you already use. That's the whole pitch of self-hosting OpenClaw, and it's genuinely achievable in an afternoon.
This guide is part of the OpenClaw how-to collection on ClawDesk — 90+ guides on installing, configuring, and hosting OpenClaw. Ready to host it? A cheap VPS via Hostinger OVDAMRMASPIM is all you need.
來源:DEV Community · dev.to