---
title: 'Tutorial: How to Secure Access to OpenClaw (AI Agent) with Access Server on Linux'
canonical: https://openvpn.net/as-docs/v3/tutorials/tutorial--secure-openclaw-ai-ai-access/
product: Access Server Docs
description: Secure OpenClaw with OpenVPN Access Server. Deploy the AI gateway, configure VPN routing rules, and restrict access so OpenClaw is reachable only through the VPN.
---

# Tutorial: How to Secure Access to OpenClaw (AI Agent) with Access Server on Linux

## Overview

This tutorial explains how to secure access to [OpenClaw](https://openclaw.ai/), an AI agent gateway, using Access Server on any Linux server. By routing traffic through Access Server, you can ensure that users can access the OpenClaw service only while connected to the VPN.

In this example scenario:

[OpenClaw is an AI agent gateway](https://docs.openclaw.ai/) that connects chat applications (such as WhatsApp, Telegram, Discord, and iMessage) to AI agents like GPT-4o or Claude.

This tutorial shows how to:

- Deploy OpenClaw.
- Configure its web gateway.
- Deploy Caddy.
- Restrict access using Access Server routing rules.
- Verify that access works only through the VPN.

## Prerequisites

- Access Server (recommended 3.1.0 or newer to use Domain Routing)
- A Linux server where OpenClaw will be installed

  > **Tip**
  >
  > OpenClaw can be resource-intensive depending on the AI provider and workload. For best performance, deploy it on a server with at least 2 vCPUs and 4 GB of RAM.
- SSH access to your OpenClaw server
- A VPN client for connecting to Access Server

> **Note**
>
> In our documentation, we use example IPv4 addresses and subnets [reserved for documentation](https://en.wikipedia.org/wiki/Reserved_IP_addresses#IPv4), such as `192.0.2.0/24`, `198.51.100.0/24`, and `203.0.113.0/24`.
>
> Ensure you replace them with valid IPv4 addresses and subnets for your network(s).

## Step 1: Deploy a Linux server for OpenClaw

Deploy a new Linux server in the same environment as your Access Server. This tutorial uses Ubuntu 24.04 LTS.

> **Important**
>
> Deploy OpenClaw in the same cloud provider or network as your Access Server so both systems share the same private network. If you need to deploy them in separate networks or VPCs, use VPC peering to allow Access Server to route traffic to the OpenClaw server. Refer to your cloud provider's documentation for VPC peering steps.

1. Create a new Linux server instance in your environment (for example, an EC2 instance, a VM, or a bare-metal server running Ubuntu 24.04 LTS).
2. Confirm that you can connect to the server via SSH or console before proceeding.

## Step 2: Connect to your server and install OpenClaw

After the instance launches, connect to it using SSH and install OpenClaw.

1. Open a terminal or SSH client.
2. Connect to the server using your SSH user. Example command:

   ```
   ssh -i /path/key-pair-name.pem <ssh-user>@<instance-ipv4-address>
   ```

   Replace `/path/key-pair-name.pem` with your private SSH key.

   Replace `<ssh-user>` with your SSH user.

   Replace `<instance-ipv4-address>` with your instance's public IP address.

   > **Tip**
   >
   > You can refer to [Connect to Access Server via SSH using PuTTY](https://openvpn.net/as-docs/v3/tutorials/tutorial--connect-with-putty.md) for steps to connect with the PuTTY SSH client from a Windows computer. If you have a different configuration, please follow DigitalOcean’s instructions on connecting to your instance.
3. Install OpenClaw:

   ```
   curl -fsSL https://openclaw.ai/install.sh | bash
   ```

   The OpenClaw Installer handles Node detection, installation, and onboarding automatically. During onboarding, you can configure your AI provider and model access key, or skip and configure them later. For more, refer to [OpenClaw Install](https://docs.openclaw.ai/install).
4. If you skipped onboarding and want to run it again later:

   ```
   openclaw onboard --install-daemon
   ```

## Step 3: Retrieve the OpenClaw gateway token

You need the OpenClaw gateway token to access the dashboard. There are several ways to retrieve it.

### Option A — From the onboarding output:

1. Near the end of onboarding, the token appears in the **Dashboard ready** output:

   ```
   ◇  Dashboard ready ──────────────────────────────────────────────╮
   │                                                                 │
   │  Dashboard link (with token):                                   │
   │  http://127.0.0.1:18789/#token=ABCDE12345                       │
   │  Copy/paste this URL in a browser on this machine to control    │
   │  OpenClaw.                                                      │
   ```
2. Copy the token value (for example, `ABCDE12345`) and store it securely. You'll use it later to access the OpenClaw gateway.

### Option B — From the dashboard command:

1. Run:

   ```
   openclaw dashboard --no-open
   ```

   - Example output:

     ```
     Dashboard URL: http://127.0.0.1:18789/#token=ABCDE12345
     ```
2. Copy the token value (for example, `ABCDE12345`) and store it securely. You'll use it later to access the OpenClaw gateway.

### Option C — From the config file:

1. Run:

   ```
   grep -oP '"token"\s*:\s*"\K[^"]+' ~/.openclaw/openclaw.json
   ```

   - Example output:

     ```
     ABCDE12345
     ```
2. Copy the token value (for example, `ABCDE12345`) and store it securely. You'll use it later to access the OpenClaw gateway.

## Step 4: Install and configure Caddy for OpenClaw

Caddy acts as the web server for OpenClaw. Configure it to listen only on the server's private IP address.

1. Install Caddy. Refer to the [Caddy installation documentation](https://caddyserver.com/docs/install) for your Linux distribution.
2. Retrieve the server's private IP address (in this case, we'll get the one for eth1):

   ```
   PRIVATE_IP=$(ip -4 addr show eth1 | grep -o 'inet [0-9.]*' | cut -d' ' -f2)
   ```

   - Example output:

     ```
     192.0.2.5
     ```
3. Edit the Caddy configuration to listen only on the private IP:

   ```
   sudo tee /etc/caddy/Caddyfile > /dev/null <<EOF
      ${PRIVATE_IP} {
          reverse_proxy localhost:18789
      }
   EOF
   ```
4. Restart Caddy to apply the configuration:

   ```
   systemctl restart caddy
   ```
5. Verify Caddy is running:

   ```
   systemctl status caddy
   ```
6. Verify that OpenClaw is listening on port `18789`:

   ```
   netstat -tulpn | grep 18789
   ```

   - Example output:

     ```
     tcp        0      0 127.0.0.1:18789         0.0.0.0:*               LISTEN      3376/openclaw-gatew
     ```
7. If `netstat` isn't installed:
   - **Ubuntu/Debian:** `apt install net-tools`
   - **RHEL:** `dnf install net-tools`

### Optional: Configure a domain name

Instead of using a private IP address, you can use a domain name. This lets you configure [domain routing](https://openvpn.net/access-server/features/domain-routing/) in Access Server. Example domain: `openclaw.example.com`.

1. Edit the Caddy configuration file to use the domain name:

   ```
   sudo tee /etc/caddy/Caddyfile > /dev/null <<EOF
      <DOMAIN_NAME> {
         tls internal
         reverse_proxy localhost:18789
      }
   EOF
   ```

   Replace `<DOMAIN_NAME>` with the domain associated with your OpenClaw server.
2. Restart Caddy:

   ```
   systemctl restart caddy
   ```

## Step 5: Configure Access Server to secure OpenClaw access

To restrict access to OpenClaw, configure Access Server routing rules so traffic to the OpenClaw host is only available through the VPN.

> **Important**
>
> If your OpenClaw instance is deployed on a specific cloud provider (such as AWS), deploy your Access Server on that cloud provider as well, so both systems share the same private network.
>
> You can also deploy OpenClaw in a different VPC and connect it to Access Server using VPC peering. This allows Access Server to securely route traffic to the OpenClaw server across VPC networks.
>
> Refer to your cloud provider documentation for this.

1. Sign in to the Access Server Admin Web UI.
2. Click **Access Controls**.
   - The **Group and User Access Rules** tab is displayed.
3. Click the **Global Access Rules** tab.
4. Under **IP Addresses and Subnets**, select the routing mode **NAT**.
   - This makes the source IP appear as the Access Server private IP.
5. Enter the OpenClaw server private IP in the **IP Addresses and Subnets** field. Example:

   ```
   192.0.2.5
   ```
6. Click **Save** and **Restart**.

### Optional: Configure domain routing

If you configured a domain earlier:

1. Stay on the **Global Access Rules** tab.
2. Under **Domains**, select **NAT**.
3. Enter the domain. Example:

   ```
   openclaw.example.com
   ```
4. Click **Save** and **Restart**.

## Step 6: Verify access through the VPN

Now confirm that OpenClaw can only be accessed through the VPN.

1. Connect to the Access Server VPN.
2. Open a web browser.
3. Navigate to the OpenClaw gateway URL:

   ```
   https://<openclaw-private-ip>/#token=<openclaw-token>
   ```

   Replace:
   - `<openclaw-private-ip>` with the private IP.
   - `<openclaw-token>` with your gateway token.

   Example:

   ```
   https://192.0.2.5/#token=ABCDE12345
   ```

   If using a domain:

   ```
   https://openclaw.example.com/#token=ABCDE12345
   ```
4. The OpenClaw gateway dashboard should display.
5. Disconnect from the VPN and try to access the public IP address. The connection should fail, confirming that access is restricted to VPN users.

## Step 7: Fix dashboard errors on first login

When you open the OpenClaw dashboard for the first time, two errors may appear. Follow the steps below to resolve them.

### "Origin not allowed" error

The Control UI rejects requests from origins not in its allowlist. Add your OpenClaw private IP or domain to the allowlist.

1. Run the following command, replacing `<openclaw-private-ip>` with your private IP:

   ```
   openclaw config set gateway.controlUi.allowedOrigins '["https://<openclaw-private-ip>"]' --strict-json
   ```

   Example:

   ```
   openclaw config set gateway.controlUi.allowedOrigins '["https://192.0.2.5"]' --strict-json
   ```

   If using a domain:

   ```
   openclaw config set gateway.controlUi.allowedOrigins '["https://openclaw.example.com"]' --strict-json
   ```
2. Restart the OpenClaw gateway service:

   ```
   openclaw gateway restart
   ```
3. Refresh the OpenClaw dashboard. The "origin not allowed" error should no longer appear.

### "Pairing required" error

This error is expected. The gateway requires device approval as an additional security layer on top of token authentication.

1. List pending device requests:

   ```
   openclaw devices list
   ```

   - A pending request displays with a Request ID. Example:

     ```
     ABCD-1234-EFGH-5678
     ```
2. Approve the request, replacing `<request-id>` with your Request ID:

   ```
   openclaw devices approve <request-id>
   ```

   Example:

   ```
   openclaw devices approve ABCD-1234-EFGH-5678
   ```

   - If successful, an **Approved** confirmation is displayed.
3. Refresh the OpenClaw dashboard. You should now be signed in with no errors.

## Step 8: Security recommendations

For additional security guidance for OpenClaw, refer to the [OpenClaw Security documentation](https://openclaw.ai/security).

## Related pages

- [Tutorial: How to Secure Access to OpenClaw (AI Agent) with Access Server (DigitalOcean)](https://openvpn.net/as-docs/v3/tutorials/tutorial--secure-openclaw-ai-ai-access.md)
- [Tutorial: How to Back Up Access Server Configuration](https://openvpn.net/as-docs/v3/tutorials/tutorial--configuration-backup.md)
- [Access Server Domain Routing](https://openvpn.net/access-server/features/domain-routing/)
- [Connect to Access Server via SSH using PuTTY](https://openvpn.net/as-docs/v3/tutorials/tutorial--connect-with-putty.md)

---

Prev: [Tutorial: Using AWS Transit Gateway with Access Server](https://openvpn.net/as-docs/v3/tutorials/tutorial--aws-transit-gateway.md)
Next: [Tutorial: How to Secure Access to OpenClaw (AI Agent) on DigitalOcean with Access Server](https://openvpn.net/as-docs/v3/tutorials/tutorial--secure-openclaw-ai-access-digitalocean.md)
Index: https://openvpn.net/as-docs/llms.txt
