大多数人部署 OpenClaw 的流程是:买服务器 → 一键部署 → 配置 API Key → 开始用。但很少有人在部署完成后做安全加固。
一台暴露在公网上的服务器,如果不做安全配置,等于给攻击者留了一扇敞开的门。你的 API Key、对话数据、甚至整个服务器 都可能被入侵。
本文将覆盖 OpenClaw 部署后必须做的安全加固措施。
在 Lighthouse 控制台的防火墙管理页面,设置以下规则:
| 协议 | 端口 | 策略 | 说明 |
|---|---|---|---|
| TCP | 22 | 允许(限 IP) | SSH 登录 |
| TCP | 3210 | 允许(限 IP) | OpenClaw Dashboard |
| TCP | 443 | 允许 | HTTPS(如配置) |
| 其他 | 全部 | 拒绝 | 默认拒绝 |
核心原则:只开放必要的端口,SSH 端口严格限制为你的 IP。
部署参考:腾讯云 OpenClaw 专题页
# 生成密钥对(在本地执行)
ssh-keygen -t ed25519 -C "your-email@example.com"
# 将公钥上传到服务器
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your-server-ip
# 修改 SSH 配置
vim /etc/ssh/sshd_config
修改以下参数:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin prohibit-password
重启 SSH 服务:
systemctl restart sshd
# 在 sshd_config 中
Port 2222 # 改为非默认端口
记得在防火墙中开放新端口。
apt install fail2ban -y
systemctl enable fail2ban
fail2ban 会自动封禁多次登录失败的 IP。
Dashboard 的登录密码必须满足:
你的大模型 API Key 存储在 OpenClaw 的配置中。保护措施:
如果你接入了 Telegram、飞书、钉钉等平台,Webhook 端点会暴露在公网:
将 OpenClaw Dashboard 从 HTTP 升级到 HTTPS:
# 安装 Nginx 和 Certbot
apt install nginx certbot python3-certbot-nginx -y
# 申请证书(需要域名)
certbot --nginx -d your-domain.com
Nginx 配置示例:
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
location / {
proxy_pass http://localhost:3210;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
将域名接入 Cloudflare,开启强制 HTTPS和 WAF 防护,免费且简单。
apt install unattended-upgrades -y
dpkg-reconfigure -plow unattended-upgrades
定期检查关键日志:
# 系统登录日志
tail -100 /var/log/auth.log
# OpenClaw 日志
docker logs --tail 200 openclaw
# Nginx 访问日志(如有)
tail -100 /var/log/nginx/access.log
使用腾讯云的快照功能定期备份:
部署教程:云上 OpenClaw 一键秒级部署指南
安全加固不是"可选项",而是必选项。花 30 分钟做好以上配置,可以避免未来数小时甚至数天的事故处理。
你的 OpenClaw 实例承载着 API Key、对话数据、业务逻辑——保护好它们,就是保护好你的资产。
安全部署从这里开始:腾讯云 OpenClaw 一键部署