如何透過遠端 Gateway 執行 OpenClaw.app
開發時最煩人的事情之一,就是要把本地端的 App 連接到遠端伺服器上的服務。如果你不想把埠號(Port)暴露在公網上,又懶得每次手動連線,SSH Tunnel 就是你的救星。
這份指南會帶你一步步搞定 OpenClaw.app 與遠端 Gateway 的連線,讓你像在本地端開發一樣順暢。
內容已併入 Remote Access。請參閱該頁面以獲取最新指南。
搭配 Remote Gateway 執行 OpenClaw.app
Section titled “搭配 Remote Gateway 執行 OpenClaw.app”OpenClaw.app 使用 SSH Tunnel 連接到遠端 Gateway。這份指南會教你如何設定。
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步驟 1:新增 SSH 設定
Section titled “步驟 1:新增 SSH 設定”編輯 ~/.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> 替換成你的實際數值。
步驟 2:複製 SSH Key
Section titled “步驟 2:複製 SSH Key”將你的公鑰(Public Key)複製到遠端機器(只需輸入一次密碼):
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP>步驟 3:設定 Gateway Token
Section titled “步驟 3:設定 Gateway Token”launchctl setenv OPENCLAW_GATEWAY_TOKEN "<your-token>"步驟 4:啟動 SSH Tunnel
Section titled “步驟 4:啟動 SSH Tunnel”ssh -N remote-gateway &步驟 5:重啟 OpenClaw.app
Section titled “步驟 5:重啟 OpenClaw.app”# Quit OpenClaw.app (⌘Q), then reopen:open /path/to/OpenClaw.app現在 App 會透過 SSH Tunnel 連接到遠端 Gateway。
登入時自動啟動 Tunnel
Section titled “登入時自動啟動 Tunnel”為了讓 SSH Tunnel 在你登入時自動啟動,可以建立一個 Launch Agent。
建立 PLIST 檔案
Section titled “建立 PLIST 檔案”將以下內容儲存為 ~/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>載入 Launch Agent
Section titled “載入 Launch Agent”launchctl bootstrap gui/$UID ~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist現在 Tunnel 會:
- 在你登入時自動啟動
- 如果當掉會自動重啟
- 持續在背景執行
舊版註記:如果存在任何舊的 com.openclaw.ssh-tunnel LaunchAgent,請將其移除。
檢查 Tunnel 是否正在執行:
ps aux | grep "ssh -N remote-gateway" | grep -v greplsof -i :18789重啟 Tunnel:
launchctl kickstart -k gui/$UID/ai.openclaw.ssh-tunnel停止 Tunnel:
launchctl bootout gui/$UID/ai.openclaw.ssh-tunnel| 組件 | 功能 |
|---|---|
LocalForward 18789 127.0.0.1:18789 | 將本地端 Port 18789 轉發到遠端 Port 18789 |
ssh -N | 執行 SSH 但不執行遠端指令(僅進行 Port Forwarding) |
KeepAlive | 如果 Tunnel 崩潰會自動重啟 |
RunAtLoad | 當 Agent 載入時啟動 Tunnel |
OpenClaw.app 會連線到你本地機器的 ws://127.0.0.1:18789。SSH Tunnel 會將該連線轉發到執行 Gateway 的遠端機器 Port 18789。
如有任何問題,請諮詢 AI Setup Assistant。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。