OpenClaw 的 Gateway 默认只监听本地回环(127.0.0.1), 安全的远程访问需要通过 SSH 隧道或 Tailscale 来建立。
三种远程架构,选适合你的
架构 1:VPS 常驻 Gateway(推荐,always-on)
VPS(24小时在线)
├── OpenClaw Gateway 运行中
└── 通过 Tailscale 或 SSH 隧道对外提供服务
你的所有设备
├── Mac → 通过 Tailscale 连接,控制面板和 WebChat 都能用
├── iPhone → Telegram/WhatsApp 消息直接到 VPS Gateway
└── 笔记本关机了 → AI 助手仍在线
最适合:主力机器会关机/休眠,想让 AI 24 小时在线的用户。
架构 2:桌面机跑 Gateway,笔记本远程控制
桌面机(家里,持续开机)
└── OpenClaw Gateway
外出时
└── 笔记本通过 SSH 隧道连接桌面机的 Gateway
macOS App → Settings → "OpenClaw runs on: Remote"
最适合:有一台持续开机的桌面机、笔记本只是终端的用户。
架构 3:笔记本跑 Gateway,其他设备临时访问
笔记本(主力机)
└── OpenClaw Gateway(本地模式)
偶尔从 iPad 或家里其他设备访问
└── SSH 隧道到笔记本(笔记本需要在线)
最适合:主机明确是笔记本、偶尔需要从其他设备访问的用户。
方案一:SSH 隧道(通用方案)
在任何能 SSH 的机器上都可以用:
bash
# 把远程机器的 18789 端口转发到本地
ssh -N -L 18789:127.0.0.1:18789 user@your-server-ip
# 保持后台运行
ssh -fN -L 18789:127.0.0.1:18789 user@your-server-ip
# 隧道建立后,本地访问远程 Gateway
openclaw status # 会通过隧道连接到远程 Gateway
open http://127.0.0.1:18789 # 打开控制面板持久化 SSH 隧道(使用 autossh):
bash
# macOS
brew install autossh
# 开机自动建立隧道
autossh -M 0 -f -N -o "ServerAliveInterval=30" -o "ServerAliveCountMax=3" -L 18789:127.0.0.1:18789 user@your-server方案二:Tailscale(推荐,最简洁)
Tailscale 创建私有网络,Gateway 可以绑定到 Tailscale IP, 所有加入 tailnet 的设备都能直接访问:
bash
# 1. 服务器端安装 Tailscale
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up
# 2. 获取 Tailscale IP(通常是 100.x.x.x)
tailscale ip -4
# 3. 配置 OpenClaw 绑定到 tailnet
# ~/.openclaw/openclaw.json
{
"gateway": {
"bind": "tailnet", // 监听 Tailscale IP
"port": 18789,
"auth": {
"token": "your-secure-token" // tailnet 也要加认证
}
}
}
# 4. 本地设备也加入 tailnet 后,直接访问
open http://100.x.x.x:18789 # 控制面板Tailscale Serve 暴露控制面板(HTTPS,自带证书):
bash
# 通过 Tailscale Serve 暴露,自动 HTTPS
tailscale serve --bg --https=443 http://127.0.0.1:18789
# 访问
open https://your-machine.tailnet-name.ts.net对应的 OpenClaw 配置:
json
{
"gateway": {
"auth": {
"allowTailscale": true // 允许 Tailscale identity 认证(Control UI)
}
}
}macOS App 的 Remote over SSH 模式
macOS App 内置 SSH 远程管理,自动建立和维护隧道:
菜单栏图标 → 设置 → General
"OpenClaw runs on:" → 选择 "Remote machine"
填写:
- Host: your-server.com 或 IP
- User: ubuntu
- Port: 22(默认)
- SSH Key: 选择私钥文件(~/.ssh/id_rsa)
App 会自动:
- 建立 SSH 隧道(转发 Gateway 端口)
- 健康检查远程 Gateway 状态
- WebChat 通过隧道连接
CLI 持久化远程配置
不想每次都手动建隧道,可以在配置文件里设置默认远程:
json
{
"gateway": {
"mode": "remote",
"remote": {
"url": "ws://127.0.0.1:18789",
"token": "your-token"
}
}
}这样所有 openclaw CLI 命令默认操作远程 Gateway(需要先建立 SSH 隧道)。
认证凭据优先级
远程访问时,Token 解析顺序(从高到低):
远程模式:
1. 命令行参数 --token
2. OPENCLAW_GATEWAY_TOKEN 环境变量
3. openclaw.json gateway.remote.token
4. openclaw.json gateway.auth.token(兜底)
本地模式:
1. OPENCLAW_GATEWAY_TOKEN 环境变量
2. gateway.auth.token
3. gateway.remote.token(本地模式的远程兜底)
安全要点
✅ 推荐:
- Gateway bind: loopback + SSH/Tailscale 隧道
- 非 loopback 绑定必须设置 auth.token 或 auth.password
- 使用 wss:// 时用 gateway.remote.tlsFingerprint 固定证书
⚠️ 注意:
- 不要把 Gateway 直接暴露到公网(不加认证)
- ws:// 明文只在 loopback 安全,tailnet 内也要加认证
- Tailscale Serve + allowTailscale: true 只对 Control UI,
HTTP API 仍然需要 token/password
来源:OpenClaw 官方文档 - docs.openclaw.ai/gateway/remote