跳转到内容

远程 Gateway(网关) 网关 设置

此内容已合并到Remote Access。请参阅该页面以获取最新指南。

运行使用远程Gateway(网关)的 OpenClaw.app

Section titled “运行使用远程Gateway(网关)的 OpenClaw.app”

OpenClaw.app 使用 SSH 隧道连接到远程网关。本指南将向您展示如何进行设置。

flowchart TB
subgraph Client["Client Machine"]
direction TB
A["OpenClaw.app"]
B["ws://127.0.0.1:18789\n(local port)"]
T["SSH Tunnel"]
A --> B
B --> T
end
subgraph Remote["Remote Machine"]
direction TB
C["Gateway WebSocket"]
D["ws://127.0.0.1:18789"]
C --> D
end
T --> C

编辑 ~/.ssh/config 并添加:

Host remote-gateway
HostName <REMOTE_IP> # e.g., 172.27.187.184
User <REMOTE_USER> # e.g., jefferson
LocalForward 18789 127.0.0.1:18789
IdentityFile ~/.ssh/id_rsa

<REMOTE_IP><REMOTE_USER> 替换为您的值。

将您的公钥复制到远程机器(输入一次密码):

Terminal window
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP>
Terminal window
launchctl setenv OPENCLAW_GATEWAY_TOKEN "<your-token>"
Terminal window
ssh -N remote-gateway &
Terminal window
# Quit OpenClaw.app (⌘Q), then reopen:
open /path/to/OpenClaw.app

应用程序现在将通过 SSH 隧道连接到远程网关。


要在登录时自动启动 SSH 隧道,请创建一个 Launch Agent。

将此保存为 ~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<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>
</plist>
Terminal window
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist

隧道现在将:

  • 登录时自动启动
  • 崩溃时自动重启
  • 在后台持续运行

遗留说明:如果存在,请删除任何残留的 com.openclaw.ssh-tunnel LaunchAgent。


检查隧道是否正在运行:

Terminal window
ps aux | grep "ssh -N remote-gateway" | grep -v grep
lsof -i :18789

重启隧道:

Terminal window
launchctl kickstart -k gui/$UID/ai.openclaw.ssh-tunnel

停止隧道:

Terminal window
launchctl bootout gui/$UID/ai.openclaw.ssh-tunnel

组件作用
LocalForward 18789 127.0.0.1:18789将本地端口 18789 转发到远程端口 18789
ssh -N不执行远程命令的 SSH(仅端口转发)
KeepAlive隧道崩溃时自动重启
RunAtLoad代理加载时启动隧道

OpenClaw.app 连接到您客户端机器上的 ws://127.0.0.1:18789。SSH 隧道将该连接转发到运行 Gateway(网关) 的远程机器上的端口 18789。