OpenClaw を安全にリモートアクセスする方法
SSH トンネル、リバースプロキシ、VPN を使用して OpenClaw ゲートウェイを安全に公開し、セキュリティを維持しながらリモートアクセスする方法を学びます。
OpenClaw Guides
Tutorial Authors
なぜリモートアクセスが必要か?
デフォルトでは、OpenClaw は 127.0.0.1(ローカルホストのみ)にバインドされており、これは最も安全な設定です。ただし、以下の場合にリモートアクセスが必要になることがあります:
- ホームサーバーで OpenClaw を実行し、外出先からアクセス
- VPS でホストし、複数のデバイスから接続
- ローカルネットワークで AI アシスタントを共有
警告: 適切な認証と暗号化なしに OpenClaw を直接インターネットに公開しないでください。このガイドでは安全な方法のみを説明します。
方法1:SSH トンネル(個人使用に推奨)
SSH トンネルは、個人的なリモートアクセスで最もシンプルで安全な方法です。
リモートサーバーで
OpenClaw が localhost で実行されていることを確認:
openclaw gateway start # Gateway listening on http://127.0.0.1:18789
ローカルマシンで
SSH トンネルを作成:
ssh -L 18789:localhost:18789 user@your-server-ip
これでローカルマシンの http://localhost:18789 から OpenClaw にアクセスできます。
autossh で永続的な SSH トンネル
自動再接続するトンネルの場合:
# autossh をインストール # macOS brew install autossh # Ubuntu/Debian sudo apt install autossh # 永続的なトンネルを作成 autossh -M 0 -f -N -L 18789:localhost:18789 user@your-server-ip
方法2:Nginx リバースプロキシ
より高度な設定では、SSL 終端を備えた Nginx をリバースプロキシとして使用します。
Nginx と Certbot をインストール
# Ubuntu/Debian sudo apt update sudo apt install nginx certbot python3-certbot-nginx
Nginx を設定
/etc/nginx/sites-available/openclaw を作成:
server {
listen 80;
server_name openclaw.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
サイトを有効化:
sudo ln -s /etc/nginx/sites-available/openclaw /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx
Let's Encrypt で SSL を追加
sudo certbot --nginx -d openclaw.yourdomain.com
基本認証を追加
パスワードファイルを生成:
sudo apt install apache2-utils sudo htpasswd -c /etc/nginx/.htpasswd your-username
Nginx 設定を更新:
server {
listen 443 ssl;
server_name openclaw.yourdomain.com;
# SSL 設定は certbot が追加...
location / {
auth_basic "OpenClaw Access";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://127.0.0.1:18789;
# ... 他のプロキシ設定
}
}
方法3:WireGuard VPN
最高のセキュリティのために、VPN を使用してホームネットワークにアクセスします。
WireGuard をインストール
# サーバー(Ubuntu/Debian) sudo apt install wireguard # キーを生成 wg genkey | tee privatekey | wg pubkey > publickey
サーバー設定
/etc/wireguard/wg0.conf を作成:
[Interface] PrivateKey = <server-private-key> Address = 10.0.0.1/24 ListenPort = 51820 [Peer] PublicKey = <client-public-key> AllowedIPs = 10.0.0.2/32
クライアント設定
[Interface] PrivateKey = <client-private-key> Address = 10.0.0.2/24 [Peer] PublicKey = <server-public-key> Endpoint = your-server-ip:51820 AllowedIPs = 10.0.0.1/32 PersistentKeepalive = 25
WireGuard を開始
# サーバー sudo wg-quick up wg0 sudo systemctl enable wg-quick@wg0 # クライアント sudo wg-quick up wg0
VPN IP 経由で OpenClaw にアクセス:http://10.0.0.1:18789
方法4:Cloudflare Tunnel(ゼロトラスト)
Cloudflare Tunnel はポートを公開せずに安全なアクセスを提供します。
cloudflared をインストール
# macOS brew install cloudflare/cloudflare/cloudflared # Linux curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb sudo dpkg -i cloudflared.deb
認証してトンネルを作成
cloudflared tunnel login cloudflared tunnel create openclaw
トンネルを設定
~/.cloudflared/config.yml を作成:
tunnel: <tunnel-id>
credentials-file: /home/user/.cloudflared/<tunnel-id>.json
ingress:
- hostname: openclaw.yourdomain.com
service: http://localhost:18789
- service: http_status:404
トンネルを実行
cloudflared tunnel route dns openclaw openclaw.yourdomain.com cloudflared tunnel run openclaw
セキュリティベストプラクティス
1. レート制限を有効化
~/.openclaw/openclaw.json で:
{
"security": {
"rateLimiting": {
"enabled": true,
"maxRequests": 60,
"windowMs": 60000
}
}
}
2. 強力な API キーを使用
# 定期的に API キーをローテーション openclaw config set api-key
3. アクセスログを監視
# ゲートウェイログを確認 openclaw logs --follow
4. Fail2Ban を設定(Nginx 用)
sudo apt install fail2ban # /etc/fail2ban/jail.local を作成 [nginx-http-auth] enabled = true
比較表
| 方法 | セキュリティ | 複雑さ | 最適な用途 | |--------|----------|------------|----------| | SSH トンネル | 高 | 低 | 個人使用 | | Nginx + SSL | 高 | 中 | パブリックアクセス | | WireGuard VPN | 非常に高い | 中 | チームアクセス | | Cloudflare Tunnel | 高 | 低 | ゼロトラスト設定 |