本文适合:重视数据安全的 OpenClaw 用户
预计阅读:12 分钟
难度等级:⭐⭐⭐
你可能会担心:
• 我的聊天记录会被泄露吗?
• API Key 存在哪里?安全吗?
• OpenClaw 会上传我的数据吗?
• 如何防止别人访问我的 AI 助手?
这篇指南帮你彻底搞懂安全机制,保护你的隐私。
━ 🔒 核心原则:本地优先 ━
OpenClaw 的安全优势
和云端 AI 服务不同,OpenClaw 采用本地优先架构:
✅ 本地运行:Gateway 运行在你的机器上,不是云端服务器
✅ 本地存储:配置、日志、会话数据都在本地
✅ 数据不出境:只有调用 AI 模型时才发送请求
✅ 完全可控:你可以随时查看、删除所有数据
数据流向图
[你的消息] → [本地 Gateway] → [AI 模型 API] → [本地 Gateway] → [回复给你]
关键点:只有你主动发送的消息才会离开本地,OpenClaw 不会偷偷上传任何东西。
━ 🔒 API Key 安全管理 ━
API Key 存在哪里?
所有敏感信息存储在:
~/.openclaw/openclaw.json
文件权限
确保只有你能读取:
chmod 600 ~/.openclaw/openclaw.json
查看当前权限
ls -la ~/.openclaw/openclaw.json
# 应该显示:-rw------- 1 you you ...
最佳实践
• ❌ 不要把 openclaw.json 提交到 Git
• ❌ 不要在公开场合截图配置文件
• ✅ 定期轮换 API Key(每 3-6 个月)
• ✅ 使用环境变量存储敏感信息
使用环境变量
更安全的方式是用环境变量:
export OPENAI_API_KEY="sk-xxx"
export ANTHROPIC_API_KEY="sk-xxx"
然后在 openclaw.json 中引用:
{
"agents": {
"authProfiles": {
"openai": {"apiKey": "${OPENAI_API_KEY}"}
}
}
}
━ 🔒 访问控制 ━
限制谁能访问你的 AI
1️⃣ 飞书渠道:配置白名单
只允许特定群/用户访问:
openclaw config.patch '{
"plugins": {
"entries": {
"lark": {
"config": {
"allowedChats": ["oc_xxx", "ou_xxx"]
}
}
}
}
}'
2️⃣ Discord:限制服务器/频道
openclaw config.patch '{
"plugins": {
"entries": {
"discord": {
"config": {
"allowedGuilds": ["123456789"],
"allowedChannels": ["987654321"]
}
}
}
}
}'
3️⃣ Gateway Token 保护
Gateway Token 是访问 Gateway 的凭证,绝不能泄露:
openclaw config.get gateway.token
定期更换 Token:
openclaw gateway regenerate-token
━ 🔒 数据隐私保护 ━
会话数据管理
1️⃣ 查看存储的数据
ls ~/.openclaw/data/
2️⃣ 清除历史会话
rm -rf ~/.openclaw/data/sessions/*
3️⃣ 设置自动清理
定期清理旧会话(保留最近 7 天):
openclaw config.patch '{"gateway": {"sessionRetention": 604800}}' # 7天 = 7*24*3600
4️⃣ 禁用会话持久化
如果不需要长期记忆:
openclaw config.patch '{"gateway": {"persistSessions": false}}'
日志隐私
1️⃣ 禁用敏感日志
openclaw config.patch '{"gateway": {"logLevel": "error"}}'
2️⃣ 禁用消息内容日志
openclaw config.patch '{"gateway": {"logMessageContent": false}}'
━ 🔒 网络安全 ━
1️⃣ 使用 HTTPS
如果需要外网访问,务必配置 HTTPS:
openclaw config.patch '{"gateway": {"https": {"enabled": true, "cert": "/path/to/cert.pem", "key": "/path/to/key.pem"}}}'
2️⃣ 限制监听地址
只监听本地,不对外开放:
openclaw config.patch '{"gateway": {"host": "127.0.0.1"}}'
3️⃣ 使用防火墙
如果需要外网访问,配置防火墙规则:
# 只允许特定 IP 访问
iptables -A INPUT -p tcp --dport 443 -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j DROP
━ 🔒 备份与恢复 ━
定期备份配置
1️⃣ 备份配置文件
cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup
2️⃣ 加密备份
如果备份到云端,先加密:
tar -czf - ~/.openclaw | gpg -c > openclaw-backup.tar.gz.gpg
3️⃣ 恢复配置
gpg -d openclaw-backup.tar.gz.gpg | tar -xzf -
━ ✅ 安全 Checklist ━
照着这个清单检查一遍:
✅ openclaw.json 权限设为 600
✅ API Key 使用环境变量存储
✅ 配置渠道白名单
✅ Gateway Token 不泄露
✅ 定期清理会话数据
✅ 禁用敏感日志
✅ 外网访问使用 HTTPS
✅ 定期备份并加密
安全无小事,配置好这些,你就能放心使用 OpenClaw 了 🔒
夜雨聆风