第 9 章 - 加密存储
第 9 章 - 加密存储
9.1 加密概述
Rclone 的 crypt 后端可以在其他 Remote 上叠加一层加密层,实现:
- 文件内容加密:上传前加密,下载后解密
- 文件名加密:隐藏真实文件名
- 目录名加密:隐藏目录结构
- 透明操作:对用户完全透明,如同操作普通文件
加密架构
用户操作 → Rclone → Crypt 层(加密) → 实际后端(S3/GDrive/...)
↕
密码 + 盐 → AES-256 加密
适用场景
| 场景 | 说明 |
|---|---|
| 云端隐私保护 | 防止云存储提供商查看文件内容 |
| 合规要求 | 满足数据保护法规(如 GDPR) |
| 共享存储安全 | 在共享存储上保护个人数据 |
| 防泄露 | 即使存储账号被盗,数据仍然安全 |
9.2 创建 Crypt Remote
交互式配置
rclone config
# n) New remote
# name> encrypted
# Storage> crypt
# remote> s3:my-bucket/encrypted/ # 底层 Remote 的路径
# filename_encryption> standard # 文件名加密模式
# directory_name_encryption> true # 目录名加密
# password> your-secure-password # 加密密码
# password2> your-secure-password # 盐(可选,建议设置)
配置文件示例
# 底层 Remote
[s3]
type = s3
provider = AWS
access_key_id = AKIAIOSFODNN7EXAMPLE
secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
region = us-east-1
# 加密 Remote(基于 s3)
[encrypted]
type = crypt
remote = s3:my-bucket/encrypted/
password = $encrypted$xxxxxxxxxxxxxxxxxxxx
password2 = $encrypted$xxxxxxxxxxxxxxxxxxxx
filename_encryption = standard
directory_name_encryption = true
9.3 密码管理
密码生成
# 方式 1:交互式输入(密码会被加密存储)
rclone config # 配置 crypt 时输入
# 方式 2:使用 rclone obscure 加密密码
rclone obscure "my-secure-password"
# 输出:$encrypted$xxxxxxxxxxxxxxxxxxxx
# 方式 3:在配置文件中使用加密后的密码
[encrypted]
type = crypt
password = $encrypted$xxxxxxxxxxxxxxxxxxxx
password2 = $encrypted$xxxxxxxxxxxxxxxxxxxx
密码强度建议
| 要求 | 建议 |
|---|---|
| 长度 | ≥ 20 个字符 |
| 复杂度 | 大小写字母 + 数字 + 特殊字符 |
| 唯一性 | 不要与其他密码重复 |
| 保管 | 使用密码管理器(如 Bitwarden、1Password) |
⚠️ 密码丢失后果
密码丢失 = 数据永久丢失!
Rclone 的加密是强加密(AES-256-CTR + XSalsa20),没有密码就无法解密数据。请务必:
- 使用密码管理器保存密码
- 创建密码恢复密钥并离线保存
- 不要只依赖记忆
9.4 文件名加密模式
三种模式对比
| 模式 | 配置值 | 加密程度 | 可读性 | 适用场景 |
|---|---|---|---|---|
| Off | off | 无 | 完全可读 | 只加密内容 |
| Standard | standard | 高 | 完全不可读 | 推荐默认 |
| Obfuscate | obfuscate | 低 | 部分可读 | 伪装文件名 |
off 模式
[encrypted]
type = crypt
remote = s3:my-bucket/
filename_encryption = off
password = $encrypted$xxx
password2 = $encrypted$xxx
本地文件 → S3 存储中的文件
photos/image.jpg → photos/image.jpg (文件名不变,内容加密)
standard 模式(推荐)
[encrypted]
type = crypt
remote = s3:my-bucket/
filename_encryption = standard
directory_name_encryption = true
password = $encrypted$xxx
password2 = $encrypted$xxx
本地文件 → S3 存储中的文件
photos/image.jpg → p31v4s8g2a1q5n7r/t8k2m4j6h0f1.enc
documents/report.pdf → a9b3c7d2e6f1g5h4/i8j2k6l0m4n8.enc
obfuscate 模式
[encrypted]
type = crypt
remote = s3:my-bucket/
filename_encryption = obfuscate
password = $encrypted$xxx
password2 = $encrypted$xxx
本地文件 → S3 存储中的文件
image.jpg → vzntr.wct (简单字符替换,易被识别)
9.5 使用加密 Remote
加密 Remote 的使用方式与普通 Remote 完全相同:
# 上传文件(自动加密)
rclone copy /data/private/ encrypted:private/
# 下载文件(自动解密)
rclone copy encrypted:private/ /data/restore/
# 列出文件(显示解密后的文件名)
rclone ls encrypted:
# 同步
rclone sync /data/encrypted/ encrypted:backup/
# 挂载加密存储
rclone mount encrypted: ~/encrypted --vfs-cache-mode full
# 查看加密存储的实际内容(不通过 crypt 层)
rclone ls s3:my-bucket/encrypted/
# 显示的是加密后的文件名和内容
9.6 加密强度分析
使用的加密算法
| 组件 | 算法 | 密钥长度 |
|---|---|---|
| 文件内容 | AES-256-CTR | 256 位 |
| 文件名 | XSalsa20-Poly1305 | 256 位 |
| 目录名 | XSalsa20-Poly1305 | 256 位 |
| 密码派生 | scrypt | 可配置 |
安全性评估
- ✅ 使用行业标准加密算法
- ✅ 密码使用 scrypt 派生,抗暴力破解
- ✅ 支持盐(password2),相同密码不同盐产生不同密文
- ✅ 流式加密,不需要将整个文件加载到内存
- ⚠️ 文件长度可能会暴露文件类型信息
- ⚠️ 文件修改时间未加密
9.7 高级用法
双层加密
# 第一层:加密文件名和内容
[encrypted-layer1]
type = crypt
remote = s3:bucket/layer1/
password = $encrypted$xxx
password2 = $encrypted$xxx
# 第二层:再次加密(更安全但性能下降)
[encrypted-layer2]
type = crypt
remote = encrypted-layer1:/
password = $encrypted$yyy
password2 = $encrypted$yyy
加密挂载 + 本地同步
# 挂载加密存储
rclone mount encrypted: ~/cloud-encrypted --daemon --vfs-cache-mode full
# 本地目录同步到加密存储
rclone sync /data/sensitive/ encrypted:backup/sensitive/ --progress
跨云加密迁移
# 从加密的 S3 迁移到加密的 Google Drive
# 方式 1:通过 crypt 层(透明解密再加密)
rclone sync encrypted-s3: encrypted-gdrive: --progress
# 方式 2:直接操作底层(不推荐,密文不同)
9.8 从非加密迁移到加密
# 步骤 1:创建加密 Remote
# 已配置 [encrypted] remote
# 步骤 2:同步数据(Rclone 会自动加密)
rclone sync s3:my-bucket/plain/ encrypted: --progress
# 步骤 3:验证加密数据
rclone ls encrypted:
# 显示解密后的文件列表
rclone ls s3:my-bucket/plain/
# 显示加密后的文件列表
# 步骤 4:确认无误后删除明文数据
rclone delete s3:my-bucket/plain/ --dry-run
rclone delete s3:my-bucket/plain/
9.9 备份密码和配置
# 导出配置(包含加密密码)
rclone config file
# 复制配置文件到安全位置
# 使用 Rclone 自带的配置加密
rclone config
# s) Set configuration password
# 手动备份关键信息
cat > ~/rclone-recovery.txt << 'EOF'
Rclone Crypt Recovery Information
=================================
Remote Name: encrypted
Backend Remote: s3:my-bucket/encrypted/
Password: <your-password>
Salt (password2): <your-salt>
Filename Encryption: standard
Directory Name Encryption: true
Date: 2026-05-10
EOF
# ⚠️ 将此文件保存到安全的离线位置!
注意事项
⚠️ 密码安全:密码一旦丢失,数据将永久无法恢复。使用密码管理器,并创建离线恢复备份。
⚠️ 性能影响:加密会增加 CPU 开销。对于大文件传输,影响通常 < 5%。挂载模式下的小文件随机读写可能有更明显的影响。
⚠️ 文件长度:加密后的文件会比原文件稍大(填充 + 认证标签),通常增加 16 字节。
⚠️ 不能直接操作底层:不要直接通过底层 Remote 修改加密文件,这会导致数据损坏。始终通过 crypt Remote 操作。
💡 盐(password2):强烈建议设置。即使两个用户使用相同密码,不同的盐也会产生完全不同的密文。
💡 scrypt 参数:默认参数已足够安全。如需更高安全性,可在高级配置中调整
password2和 scrypt 参数。
扩展阅读
上一章:← 第 8 章 - 服务模式 下一章:第 10 章 - 双向同步 →