您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Linux的eCryptfs怎么使用
## 什么是eCryptfs
eCryptfs(Enterprise Cryptographic Filesystem)是Linux内核中的一个**堆叠式加密文件系统**,它能够对单个文件或目录进行透明加密。与全盘加密方案(如LUKS)不同,eCryptfs提供更细粒度的控制,适合需要选择性加密的场景。
### 核心特性
- **逐文件加密**:每个文件独立加密,密钥可不同
- **透明加解密**:读写操作自动处理
- **密钥管理灵活**:支持口令、PKI等多种方式
- **兼容性**:可叠加在现有文件系统(如ext4)之上
---
## 安装eCryptfs
大多数主流发行版已内置eCryptfs内核模块,只需安装用户态工具:
```bash
# Debian/Ubuntu
sudo apt install ecryptfs-utils
# RHEL/CentOS
sudo yum install ecryptfs-utils
# Arch Linux
sudo pacman -S ecryptfs-utils
加载内核模块:
sudo modprobe ecryptfs
sudo mount -t ecryptfs ~/Private /mnt/private
首次执行会进入交互式配置: 1. 选择加密算法(默认AES) 2. 设置密钥字节长度(通常选32) 3. 启用文件名加密(推荐y) 4. 输入挂载密码
编辑/etc/pam.d/login
添加:
auth optional pam_ecryptfs.so unwrap
session optional pam_ecryptfs.so unwrap
创建~/.ecryptfsrc
配置文件:
key=passphrase:passphrase_file=/home/user/.ecryptfs/passphrase
ecryptfs_sig=xxxxxxxxxxxxxx
ecryptfs_cipher=aes
ecryptfs_key_bytes=32
ecryptfs_passthrough=n
ecryptfs_enable_filename_crypto=y
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -pubout -out public.pem
sudo mount -t ecryptfs -o key=public.pem ~/Secure /mnt/secure
sudo ecryptfs-setup-swap
注意:此操作会格式化现有swap分区!
mount | grep ecryptfs
# 备份签名和配置文件
cp ~/.ecryptfs/ ~/ecryptfs-backup -r
# 导出加密密钥
ecryptfs-unwrap-passphrase ~/.ecryptfs/wrapped-passphrase
sudo mount -t ecryptfs -o ecryptfs_sig=xxxx,ecryptfs_fnek_sig=xxxx \
~/Encrypted /mnt/encrypted
# 创建加密目录
mkdir -p ~/Documents/Secret
mount -t ecryptfs ~/Documents/Secret ~/Documents/Secret
# 验证加密
echo "TOP SECRET" > test.txt
hexdump -C test.txt # 应显示乱码
# 加密Apache配置目录
sudo mount -t ecryptfs /etc/apache2/conf-enc /etc/apache2/conf.d
ecryptfs_enable_filename_crypto
选项ecryptfs-add-passphrase --fnek
添加文件名加密密钥umount
而非fusermount
wrapped-passphrase
文件特性 | eCryptfs | LUKS | EncFS |
---|---|---|---|
加密粒度 | 文件级 | 块设备级 | 文件级 |
性能影响 | 中等 | 低 | 高 |
密钥管理 | 灵活 | 简单 | 简单 |
系统集成度 | 高 | 最高 | 中等 |
man ecryptfs
查看完整手册/usr/share/doc/ecryptfs-utils/ecryptfs-faq.html
”`
提示:生产环境使用前,建议在测试目录验证加解密流程,并确保有完整的备份方案。对于关键系统目录加密,推荐结合LUKS全盘加密使用。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。