リモート Gateway で OpenClaw.app を実行する
OpenClaw.app は SSH トンネリングを使用してリモート Gateway に接続します。このガイドでは、その設定方法を示します。
概要
┌─────────────────────────────────────────────────────────────┐
│ クライアントマシン │
│ │
│ OpenClaw.app ──► ws://127.0.0.1:18789 (ローカルポート) │
│ │ │
│ ▼ │
│ SSH トンネル ────────────────────────────────────────────────│
│ │ │
└─────────────────────┼──────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ リモートマシン │
│ │
│ Gateway WebSocket ──► ws://127.0.0.1:18789 ──► │
│ │
└─────────────────────────────────────────────────────────────┘
クイックセットアップ
ステップ 1:SSH Config を追加
~/.ssh/config を編集して、以下を追加します:
Host remote-gateway
HostName <REMOTE_IP> # 例:172.27.187.184
User <REMOTE_USER> # 例:jefferson
LocalForward 18789 127.0.0.1:18789
IdentityFile ~/.ssh/id_rsa
<REMOTE_IP> と <REMOTE_USER> をあなたの値に置き換えてください。
ステップ 2:SSH キーをコピー
公開鍵をリモートマシンにコピーします(一度だけパスワードを入力):
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP>
ステップ 3:Gateway トークンを設定
launchctl setenv OPENCLAW_GATEWAY_TOKEN "<your-token>"
ステップ 4:SSH トンネルを起動
ssh -N remote-gateway &
ステップ 5:OpenClaw.app を再起動
# OpenClaw.app を終了(⌘Q)してから、再度開きます:
open /path/to/OpenClaw.app
アプリは SSH トンネル経由でリモート Gateway に接続するようになります。
ログイン時にトンネルを自動起動
ログイン時に SSH トンネルを自動的に起動するには、Launch Agent を作成します。
PLIST ファイルを作成
これを ~/Library/LaunchAgents/bot.molt.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>bot.molt.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 をロード
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/bot.molt.ssh-tunnel.plist
トンネルは次のようになります:
- ログイン時に自動的に起動
- クラッシュした場合は再起動
- バックグラウンドで実行し続ける
レガシー注意:残っている com.openclaw.ssh-tunnel LaunchAgent があれば削除してください。
トラブルシューティング
トンネルが実行中か確認:
ps aux | grep "ssh -N remote-gateway" | grep -v grep
lsof -i :18789
トンネルを再起動:
launchctl kickstart -k gui/$UID/bot.molt.ssh-tunnel
トンネルを停止:
launchctl bootout gui/$UID/bot.molt.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 に転送します。