Skip to content

遠端閘道設定

此內容已合併至遠端存取。請參閱該頁面以取得最新指南。

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 -NSSH 不執行遠端指令(僅進行連接埠轉送)
KeepAlive如果隧道當機則自動重新啟動
RunAtLoad當代理程式載入時啟動隧道

OpenClaw.app 連線到您用戶端機器上的 ws://127.0.0.1:18789。SSH 隧道會將該連線轉送到執行閘道的遠端機器上的連接埠 18789。