Remote access (SSH, tunnels, and tailnets)
This repo supports “remote over SSH” by keeping a single Gateway (the master) running on a dedicated host (desktop/server) and connecting clients to it.- For operators (you / the macOS app): SSH tunneling is the universal fallback.
- For nodes (iOS/Android and future devices): connect to the Gateway WebSocket (LAN/tailnet or SSH tunnel as needed).
The core idea
- The Gateway WebSocket binds to loopback on your configured port (defaults to 18789).
- For remote use, you forward that loopback port over SSH (or use a tailnet/VPN and tunnel less).
Common VPN/tailnet setups (where the agent lives)
Think of the Gateway host as “where the agent lives.” It owns sessions, auth profiles, channels, and state. Your laptop/desktop (and nodes) connect to that host.1) Always-on Gateway in your tailnet (VPS or home server)
Run the Gateway on a persistent host and reach it via Tailscale or SSH.- Best UX: keep
gateway.bind: "loopback"and use Tailscale Serve for the Control UI. - Fallback: keep loopback + SSH tunnel from any machine that needs access.
- Examples: exe.dev (easy VM) or Hetzner (production VPS).
2) Home desktop runs the Gateway, laptop is remote control
The laptop does not run the agent. It connects remotely:- Use the macOS app’s Remote over SSH mode (Settings → General → “OpenClaw runs”).
- The app opens and manages the tunnel, so WebChat + health checks “just work.”
3) Laptop runs the Gateway, remote access from other machines
Keep the Gateway local but expose it safely:- SSH tunnel to the laptop from other machines, or
- Tailscale Serve the Control UI and keep the Gateway loopback-only.
Command flow (what runs where)
One gateway service owns state + channels. Nodes are peripherals. Flow example (Telegram → node):- Telegram message arrives at the Gateway.
- Gateway runs the agent and decides whether to call a node tool.
- Gateway calls the node over the Gateway WebSocket (
node.*RPC). - Node returns the result; Gateway replies back out to Telegram.
- Nodes do not run the gateway service. Only one gateway should run per host unless you intentionally run isolated profiles (see Multiple gateways).
- macOS app “node mode” is just a node client over the Gateway WebSocket.
SSH tunnel (CLI + tools)
Create a local tunnel to the remote Gateway WS:openclaw healthandopenclaw status --deepnow reach the remote gateway viaws://127.0.0.1:18789.openclaw gateway status,openclaw gateway health,openclaw gateway probe, andopenclaw gateway callcan also target the forwarded URL via--urlwhen needed.
18789 with your configured gateway.port (or --port/OPENCLAW_GATEWAY_PORT).
Note: when you pass --url, the CLI does not fall back to config or environment credentials.
Include --token or --password explicitly. Missing explicit credentials is an error.
CLI remote defaults
You can persist a remote target so CLI commands use it by default:ws://127.0.0.1:18789 and open the SSH tunnel first.
Credential precedence
Gateway credential resolution follows one shared contract across call/probe/status paths and Discord exec-approval monitoring. Node-host uses the same base contract with one local-mode exception (it intentionally ignoresgateway.remote.*):
- Explicit credentials (
--token,--password, or toolgatewayToken) always win on call paths that accept explicit auth. - URL override safety:
- CLI URL overrides (
--url) never reuse implicit config/env credentials. - Env URL overrides (
OPENCLAW_GATEWAY_URL) may use env credentials only (OPENCLAW_GATEWAY_TOKEN/OPENCLAW_GATEWAY_PASSWORD).
- CLI URL overrides (
- Local mode defaults:
- token:
OPENCLAW_GATEWAY_TOKEN->gateway.auth.token->gateway.remote.token(remote fallback applies only when local auth token input is unset) - password:
OPENCLAW_GATEWAY_PASSWORD->gateway.auth.password->gateway.remote.password(remote fallback applies only when local auth password input is unset)
- token:
- Remote mode defaults:
- token:
gateway.remote.token->OPENCLAW_GATEWAY_TOKEN->gateway.auth.token - password:
OPENCLAW_GATEWAY_PASSWORD->gateway.remote.password->gateway.auth.password
- token:
- Node-host local-mode exception:
gateway.remote.token/gateway.remote.passwordare ignored. - Remote probe/status token checks are strict by default: they use
gateway.remote.tokenonly (no local token fallback) when targeting remote mode. - Gateway env overrides use
OPENCLAW_GATEWAY_*only.
Chat UI over SSH
WebChat no longer uses a separate HTTP port. The SwiftUI chat UI connects directly to the Gateway WebSocket.- Forward
18789over SSH (see above), then connect clients tows://127.0.0.1:18789. - On macOS, prefer the app’s “Remote over SSH” mode, which manages the tunnel automatically.
macOS app “Remote over SSH”
The macOS menu bar app can drive the same setup end-to-end (remote status checks, WebChat, and Voice Wake forwarding). Runbook: macOS remote access.Security rules (remote/VPN)
Short version: keep the Gateway loopback-only unless you’re sure you need a bind.- Loopback + SSH/Tailscale Serve is the safest default (no public exposure).
- Plaintext
ws://is loopback-only by default. For trusted private networks, setOPENCLAW_ALLOW_INSECURE_PRIVATE_WS=1on the client process as break-glass. - Non-loopback binds (
lan/tailnet/custom, orautowhen loopback is unavailable) must use gateway auth: token, password, or an identity-aware reverse proxy withgateway.auth.mode: "trusted-proxy". gateway.remote.token/.passwordare client credential sources. They do not configure server auth by themselves.- Local call paths can use
gateway.remote.*as fallback only whengateway.auth.*is unset. - If
gateway.auth.token/gateway.auth.passwordis explicitly configured via SecretRef and unresolved, resolution fails closed (no remote fallback masking). gateway.remote.tlsFingerprintpins the remote TLS cert when usingwss://.- Tailscale Serve can authenticate Control UI/WebSocket traffic via identity
headers when
gateway.auth.allowTailscale: true; HTTP API endpoints do not use that Tailscale header auth and instead follow the gateway’s normal HTTP auth mode. This tokenless flow assumes the gateway host is trusted. Set it tofalseif you want shared-secret auth everywhere. - Trusted-proxy auth is for non-loopback identity-aware proxy setups only.
Same-host loopback reverse proxies do not satisfy
gateway.auth.mode: "trusted-proxy". - Treat browser control like operator access: tailnet-only + deliberate node pairing.
macOS: persistent SSH tunnel via LaunchAgent
For macOS clients connecting to a remote gateway, the easiest persistent setup uses an SSHLocalForward config entry plus a LaunchAgent to keep the tunnel alive across reboots and crashes.
Step 1: add SSH config
Edit~/.ssh/config:
<REMOTE_IP> and <REMOTE_USER> with your values.
Step 2: copy SSH key (one-time)
Step 3: configure the gateway token
Store the token in config so it persists across restarts:Step 4: create the LaunchAgent
Save this as~/Library/LaunchAgents/ai.openclaw.ssh-tunnel.plist:
Step 5: load the LaunchAgent
com.openclaw.ssh-tunnel LaunchAgent from an older setup, unload and delete it.
Troubleshooting
Check if the tunnel is running:| Config entry | What it does |
|---|---|
LocalForward 18789 127.0.0.1:18789 | Forwards local port 18789 to remote port 18789 |
ssh -N | SSH without executing remote commands (port-forwarding only) |
KeepAlive | Automatically restarts the tunnel if it crashes |
RunAtLoad | Starts the tunnel when the LaunchAgent loads at login |