通过 SSH 隧道或 Tailnet 将客户端连接到远程 Gateway(主机)。

核心思路

  • Gateway WebSocket 默认绑定到 loopback(端口 18789)
  • 远程访问通过 SSH 端口转发或 Tailnet/VPN

常见场景

场景推荐方案
常驻 Gateway(VPS/家庭服务器)Tailscale Serve + loopback,或 SSH 隧道
桌面运行 Gateway,笔记本远程macOS app “Remote over SSH” 模式
笔记本运行 GatewaySSH 隧道到笔记本,或 Tailscale Serve

SSH 隧道

ssh -N -L 18789:127.0.0.1:18789 user@host

隧道建立后,openclaw health、openclaw status --deep 等命令通过 ws://127.0.0.1:18789 访问远程 Gateway。

CLI 远程默认配置

{
  gateway: {
    mode: "remote",
    remote: {
      url: "ws://127.0.0.1:18789",
      token: "your-token",
    },
  },
}

凭证优先级

本地模式:OPENCLAW_GATEWAY_TOKEN → gateway.auth.token → gateway.remote.token

远程模式:gateway.remote.token → OPENCLAW_GATEWAY_TOKEN → gateway.auth.token

CLI --url 覆盖时不复用隐式凭证,必须显式传 --token 或 --password。

macOS 持久 SSH 隧道(LaunchAgent)

<!-- ~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist -->
<dict>
    <key>Label</key><string>ai.openclaw.ssh-tunnel</string>
    <key>ProgramArguments</key>
    <array><string>/usr/bin/ssh</string><string>-N</string><string>remote-gateway</string></array>
    <key>KeepAlive</key><true/>
    <key>RunAtLoad</key><true/>
</dict>
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist

安全规则

  • loopback + SSH/Tailscale Serve 是最安全默认(无公网暴露)
  • 非 loopback 绑定必须启用 Gateway 认证
  • gateway.remote.tlsFingerprint 可固定远程 TLS 证书
  • Tailscale Serve 可通过 gateway.auth.allowTailscale: true 使用身份 header 认证

相关