教程

OpenClaw 远程访问完全指南:SSH 隧道、Tailscale 与跨设备连接

OpenClaw 远程访问所有方案完整教程:SSH 隧道转发(通用方案)、Tailscale 组网(推荐)、三种远程架构对比(VPS always-on/桌面机远程/笔记本本地)、macOS App 的 Remote over SSH 模式、CLI 远程默认配置(openclaw.json gateway.remote 字段)、认证凭据优先级说明、WebSocket 安全规则(loopback-only 原则)、以及 Tailscale Serve 暴露控制面板的完整步骤。

2026/3/214分钟 阅读ClaudeEagle

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

相关文章推荐

教程OpenClaw 远程访问完全指南:SSH 隧道、Tailscale 内网穿透与三种部署架构OpenClaw 远程访问完整指南:三种部署架构(VPS 常驻/桌面机+笔记本远控/本地多机访问)、SSH 端口转发隧道配置、Tailscale Serve 内网控制台与 Funnel 公网 Webhook、凭证优先级解析规则与远程安全原则。2026/3/12教程OpenClaw 接入 Google Chat:Chat API 配置、Webhook 公网暴露与 Tailscale Funnel 方案OpenClaw 接入 Google Chat 完整教程:服务账号创建与 JSON 密钥配置、Google Chat API 应用设置、三种公网暴露方案(Tailscale Funnel 推荐/Caddy 反向代理/Cloudflare Tunnel)、Bot 添加步骤,以及消息目标格式和常见问题排查。2026/3/3教程OpenClaw WebChat 指南:原生聊天 UI、Gateway WebSocket 直连与远程访问OpenClaw WebChat 完整指南:原生 SwiftUI 聊天 UI 直连 Gateway WebSocket(无需独立服务器)、chat.history/send/inject 三种消息类型、中断运行的历史持久化、Control UI 工具面板,以及通过 SSH 隧道或 Tailscale 远程访问的配置方法。2026/3/2教程OpenClaw Skills 完整指南:技能加载优先级、配置门控和 ClawHub 安装OpenClaw Skills 官方文档中文整理:技能目录结构、加载位置和优先级、per-agent 与 shared skills、插件技能、ClawHub 安装、metadata.openclaw 依赖门控、环境变量和安全边界。2026/6/4教程OpenClaw Sub-agents 使用指南:后台并行任务、结果回传和线程绑定OpenClaw Sub-agents 官方文档中文整理:什么时候用 sub-agent、如何后台并行执行任务、结果如何 announce 回主会话、thread-bound session、嵌套编排、工具权限、超时和自动归档。2026/6/4教程OpenClaw ACP Agents 完整指南:把 Codex、Claude Code、Gemini 接入聊天线程OpenClaw ACP Agents 官方文档中文整理:什么是 ACP runtime、如何把 Codex/Claude Code/Gemini CLI 绑定到聊天、current conversation bind、thread-bound session、持久会话、运行时配置和适用场景。2026/6/4