> ## Documentation Index
> Fetch the complete documentation index at: https://aiwithapex.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Remote gateway readme

# Running crocbot with a Remote Gateway

crocbot uses SSH tunneling to connect to a remote gateway. This guide shows you how to set it up.

## Overview

```
┌─────────────────────────────────────────────────────────────┐
│                        Client Machine                          │
│                                                              │
│  Control UI / CLI ──► ws://127.0.0.1:18789 (local port)      │
│                     │                                        │
│                     ▼                                        │
│  SSH Tunnel ────────────────────────────────────────────────│
│                     │                                        │
└─────────────────────┼──────────────────────────────────────┘
                      │
                      ▼
┌─────────────────────────────────────────────────────────────┐
│                         Remote Machine                        │
│                                                              │
│  Gateway WebSocket ──► ws://127.0.0.1:18789 ──►              │
│                                                              │
└─────────────────────────────────────────────────────────────┘
```

## Quick Setup

### Step 1: Add SSH Config

Edit `~/.ssh/config` and add:

```ssh theme={null}
Host remote-gateway
    HostName <REMOTE_IP>          # e.g., 192.0.2.1
    User <REMOTE_USER>            # e.g., jefferson
    LocalForward 18789 127.0.0.1:18789
    IdentityFile ~/.ssh/id_rsa
```

Replace `<REMOTE_IP>` and `<REMOTE_USER>` with your values.

### Step 2: Copy SSH Key

Copy your public key to the remote machine (enter password once):

```bash theme={null}
ssh-copy-id -i ~/.ssh/id_rsa <REMOTE_USER>@<REMOTE_IP>
```

### Step 3: Set Gateway Token

Ensure the remote Gateway has auth configured (token/password) via config or
service env vars.

### Step 4: Start SSH Tunnel

```bash theme={null}
ssh -N remote-gateway &
```

### Step 5: Open the Control UI

Open the Control UI through the tunnel:

```
http://127.0.0.1:18789/?token=<your-token>
```

You can also point the CLI at the same tunnel using `--url` and `--token`.

***

## Auto-Start Tunnel on Login

To have the SSH tunnel start automatically when you log in, create a Launch Agent.

### Create the PLIST file

Save this as `~/Library/LaunchAgents/com.crocbot.ssh-tunnel.plist`:

```xml theme={null}
<?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>com.crocbot.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>
```

### Load the Launch Agent

```bash theme={null}
launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.crocbot.ssh-tunnel.plist
```

The tunnel will now:

* Start automatically when you log in
* Restart if it crashes
* Keep running in the background

***

## Troubleshooting

**Check if tunnel is running:**

```bash theme={null}
ps aux | grep "ssh -N remote-gateway" | grep -v grep
lsof -i :18789
```

**Restart the tunnel:**

```bash theme={null}
launchctl kickstart -k gui/$UID/com.crocbot.ssh-tunnel
```

**Stop the tunnel:**

```bash theme={null}
launchctl bootout gui/$UID/com.crocbot.ssh-tunnel
```

***

## How It Works

| Component                            | 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 (just port forwarding) |
| `KeepAlive`                          | Automatically restarts tunnel if it crashes                  |
| `RunAtLoad`                          | Starts tunnel when the agent loads                           |

The Control UI connects to `ws://127.0.0.1:18789` on your client machine. The SSH tunnel forwards that connection to port 18789 on the remote machine where the Gateway is running.
