欢迎光临
我们一直在努力

安全远程访问 OpenClaw 的实用方法

RackNerd Leaderboard Banner

学习 SSH 隧道、反向代理与 VPN 技术,安全暴露 OpenClaw 网关实现远程访问,全程保障网络安全。

OpenClaw

OpenClaw

为什么需要远程访问?

默认情况下,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 反向代理

对于更高级的设置,使用 Nginx 作为带 SSL 终止的反向代理。

安装 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 零信任设置

写到最后

现在各大云平台都已经支持这个OpenClaw智能体,适合希望快速部署免去本地环境调试麻烦的团队和个人;如果不想安装在本机,可以一键部署云上OpenClaw:

腾讯云秒级部署:curl.qcloud.com/RukmXbm

阿里云一键部署:稳定不贵,不写代码,分钟级部署OpenClaw

天翼云一键部署(优惠低至1.5折):天翼云 ×OpenClaw 行动 AI 新生态 - 天翼云

京东云一键部署:3.cn/2Gc78-TT

优刻得一键部署(限时优惠5折):新春上云_云服务器_企业专属折扣1.3折起 - UCloud中立云计算

赞(0) 打赏
未经允许不得转载:软件乐园 » 安全远程访问 OpenClaw 的实用方法
RackNerd Leaderboard Banner

评论 抢沙发

🦞OpenClaw 全网爆火,一键部署教程来了!

轻量应用服务器 Lighthouse 已支持一键秒级部署,不用写代码分钟级部署,最多三步,即可拥有7x24小时在线,随时响应的AI助手!

立即部署教程指南

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册