Executando o OpenClaw.app com um Gateway Remoto¶
O OpenClaw.app usa tunelamento SSH para se conectar a um gateway remoto. Este guia mostra como configurá-lo.
Visão geral¶
%%{init: {
'theme': 'base',
'themeVariables': {
'primaryColor': '#ffffff',
'primaryTextColor': '#000000',
'primaryBorderColor': '#000000',
'lineColor': '#000000',
'secondaryColor': '#f9f9fb',
'tertiaryColor': '#ffffff',
'clusterBkg': '#f9f9fb',
'clusterBorder': '#000000',
'nodeBorder': '#000000',
'mainBkg': '#ffffff',
'edgeLabelBackground': '#ffffff'
}
}}%%
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
Configuração rápida¶
Etapa 1: Adicionar configuração SSH¶
Edite ~/.ssh/config e adicione:
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
Substitua <REMOTE_IP> e <REMOTE_USER> pelos seus valores.
Etapa 2: Copiar chave SSH¶
Copie sua chave pública para a máquina remota (digite a senha uma vez):
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP>
Etapa 3: Definir token do Gateway¶
launchctl setenv OPENCLAW_GATEWAY_TOKEN "<your-token>"
Etapa 4: Iniciar túnel SSH¶
ssh -N remote-gateway &
Etapa 5: Reiniciar o OpenClaw.app¶
# Quit OpenClaw.app (⌘Q), then reopen:
open /path/to/OpenClaw.app
O aplicativo agora se conectará ao gateway remoto por meio do túnel SSH.
Iniciar o túnel automaticamente no login¶
Para que o túnel SSH seja iniciado automaticamente quando você fizer login, crie um Launch Agent.
Criar o arquivo PLIST¶
Salve isto como ~/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>
Carregar o Launch Agent¶
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/bot.molt.ssh-tunnel.plist
O túnel agora irá:
- Iniciar automaticamente quando você fizer login
- Reiniciar se travar
- Continuar em execução em segundo plano
Nota legada: remova qualquer LaunchAgent com.openclaw.ssh-tunnel remanescente, se existir.
Solução de problemas¶
Verificar se o túnel está em execução:
ps aux | grep "ssh -N remote-gateway" | grep -v grep
lsof -i :18789
Reiniciar o túnel:
launchctl kickstart -k gui/$UID/bot.molt.ssh-tunnel
Parar o túnel:
launchctl bootout gui/$UID/bot.molt.ssh-tunnel
Como funciona¶
| Componente | O que faz |
|---|---|
LocalForward 18789 127.0.0.1:18789 |
Encaminha a porta local 18789 para a porta remota 18789 |
ssh -N |
SSH sem executar comandos remotos (apenas encaminhamento de portas) |
KeepAlive |
Reinicia automaticamente o túnel se ele travar |
RunAtLoad |
Inicia o túnel quando o agente é carregado |
O OpenClaw.app se conecta a ws://127.0.0.1:18789 na sua máquina cliente. O túnel SSH encaminha essa conexão para a porta 18789 na máquina remota onde o Gateway está em execução.