OpenClaw 是一个具有完整文件系统访问、Shell 命令执行、网页浏览能力的 AI 智能体。如果配置不当,可能导致:
风险类型 可能后果 API Key 泄露 云服务被盗用、产生高额费用 文件被窃取或删除 重要数据丢失 被用来发送垃圾消息 账号被封禁 服务器被控制 成为黑的客跳板
⚠️ 警示:2026年3月安全扫描发现,超23.4万只OpenClaw实例处于”裸奔”状态,默认管理端口直接暴露在公网!
2.1 使用独立环境运行
# ❌ 不要在与网上银行、邮件同一台电脑运行 # ✅ 建议使用单独服务器或虚拟机
2.2 创建低权限用户(Linux)
# 切勿以 root 用户身份运行 sudo adduser openclaw sudo usermod -aG sudo openclaw su - openclaw
2.3 更改默认端口
OpenClaw 默认端口容易被扫描,建议修改:
# config.yaml server: port: 18789 # 改为非标准端口
2.4 防火墙配置
# 仅允许信任IP访问 sudo ufw allow from 192.168.1.0/24 to any port 18789 sudo ufw enable
3.1 运行安全审计(首要步骤)
# 检查当前安全状态 openclaw security audit # 自动修复基础安全问题 openclaw security audit --fix # 深度安全审计(推荐定期执行) openclaw security audit --deep # 配置验证 openclaw config validate
3.2 工具权限配置(最关键)
OpenClaw 2026.3.2+ 版本默认采用最小权限原则,需手动配置:
查看当前权限配置
openclaw config get tools.profile
权限模式说明
模式 说明 推荐场景
生产环境推荐
messaging 仅对话,无工具调用 测试/演示full 完整权限 受信任环境permissive 宽松模式(应急用) 临时恢复custom 自定义白名单 ⭐生产环境推荐
配置自定义白名单(推荐)
# config.yaml tools: profile: custom custom_allowed_tools: - file_read - file_write - web_search # ⚠️ 谨慎添加以下高危工具 # - shell_exec # - system_command deny: - rm_rf - curl_post_sensitive - delete_credentials session: dmScope: restricted # 限制会话范围
快速配置命令
# 设置为完整模式(测试用) openclaw config set tools.profile full # 设置为自定义模式(生产用) openclaw config set tools.profile custom
3.3 群组/会话策略配置
# config.yaml groupPolicy: allowlist # 仅允许白名单群组 allowedGroups: - "feishu_group_id_1" - "feishu_group_id_2" session: maxDuration: 3600 # 会话最大时长(秒) requireAuth: true # 需要认证
3.4 凭证保护
# 限制 credentials 目录权限 chmod 700 ~/.openclaw/credentials chown openclaw:openclaw ~/.openclaw/credentials # 定期轮换 API 密钥 # 建议每30天更换一次
4.1 只使用官方验证技能
openclaw docker 教程
# 查看已安装插件 openclaw plugins list # 只安装官方技能(53个经过安全校验) openclaw skills install official-skill-name # 移除可疑插件 openclaw plugins remove suspicious-plugin
⚠️ 警示:2026年2月 ClawHub 插件市场发现341个恶意技能(占比12%)!
4.2 插件白名单配置
plugins: whitelist: - official-weather - official-search - official-file-manager blacklist: - unknown-network-plugin - unverified-shell-plugin
5.1 禁止公网暴露
# config.yaml network: bindAddress: 127.0.0.1 # 仅本地访问 # 如需远程访问,使用 SSH 隧道 # ssh -L 18789:localhost:18789 user@server
5.2 启用 HTTPS 加密
server: https: enabled: true certPath: /path/to/cert.pem keyPath: /path/to/key.pem
5.3 配置访问令牌
auth: enabled: true tokenExpiry: 86400 # 24小时过期 requireMFA: true # 双因素认证
6.1 启用详细日志
logging: level: info # 生产环境用 info,调试用 debug auditLog: true logPath: /var/log/openclaw/ maxAge: 30 # 日志保留30天
6.2 定期检查日志
# 查看可疑操作 grep -i "denied|error|unauthorized" /var/log/openclaw/*.log # 监控工具调用频率 openclaw logs --tool-usage --last-24h
完成配置后,请逐项检查:
检查项 命令/方法 状态 版本最新
openclaw --version □ 非root运行whoami □ 安全审计通过openclaw security audit □ 工具权限受限openclaw config get tools.profile □ 凭证目录权限ls -la ~/.openclaw/credentials □ 端口未暴露netstat -tlnp | grep 18789 □ 防火墙开启sudo ufw status □ 仅官方插件openclaw plugins list □ 日志正常记录tail /var/log/openclaw/*.log □
周期 任务 每日 检查日志异常 每周 运行
security audit --deep 每月 轮换 API 密钥、更新版本 每季度 审查插件白名单、审计访问记录
# 创建定期安全检查脚本 #!/bin/bash echo "=== OpenClaw 安全周报 ===" openclaw --version openclaw security audit --deep openclaw plugins list echo "=== 检查完成 ==="
Q1: 配置后工具无法调用怎么办?
# 临时解决方案(不推荐生产环境) openclaw config set tools.profile permissive # 推荐方案:添加具体工具到白名单 # 编辑 config.yaml 的 custom_allowed_tools
Q2: 如何恢复被锁定的配置?
# 重置为默认配置 openclaw config reset # 然后重新按本教程配置
Q3: 飞书/微信集成安全吗?
- OpenClaw 目前仅官方支持飞书
- 微信、钉钉等需通过第三方插件,风险较高
- 建议仅在企业飞书环境使用
- OpenClaw 官方安全文档:Gateway/Security 章节
- 阿里云开发者社区:OpenClaw 部署与安全配置指南
- FreeBuf:13步配置 OpenClaw 安全教程
🔐 安全原则总结:
- 最小权限:只授予必要的工具权限
- 纵深防御:多层安全措施叠加
- 定期审计:持续监控和检查
- 官方优先:只使用官方验证的插件和技能
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。
发布者:Ai探索者,转载请注明出处:https://javaforall.net/288848.html原文链接:https://javaforall.net
