eCryptFS 是 Linux 內核級企業級文件加密系統,采用疊層文件系統架構,無需分區即可透明加密目錄。本文詳解安裝配置、掛載使用、算法選擇與最佳實踐。
| 類型 | 代表工具 | 特點 | 適用場景 |
|---|---|---|---|
| 文件系統級 | eCryptFS, EncFS | 選擇性加密目錄、無需重裝系統 | 家目錄加密、敏感項目隔離 |
| 塊設備級 | LUKS/dm-crypt, VeraCrypt | 全盤加密、含 swap/tmp、性能損耗低 | 筆記本整機加密、服務器數據盤 |
# Debian/Ubuntu
sudo apt install ecryptfs-utils
# CentOS/RHEL/Fedora
sudo yum install ecryptfs-utils
# Arch Linux
sudo pacman -S ecryptfs-utils
mkdir -p ~/secret ~/secret_clear # 加密存儲目錄 + 掛載點
sudo mount -t ecryptfs ~/secret ~/secret_clear
# 提示輸入:
# Passphrase: *************
# Select cipher: 1) aes 2) blowfish 3) des3 4) cast5 5) cast6 [aes]:
# Key bytes: 1) 16 2) 32 3) 24 [16]:
# Enable plaintext passthrough? [n]
# Enable filename encryption? [y]
# Add signature to cache? [y]
sudo mount -t ecryptfs ~/secret ~/secret_clear \
-o key=passphrase:passphrase_passwd=YourPassword \
-o ecryptfs_cipher=aes \
-o ecryptfs_key_bytes=16 \
-o ecryptfs_enable_filename_crypto=y \
-o ecryptfs_passthrough=n \
-o ecryptfs_sig=$(printf "%s" "YourPassword" | sha512sum | cut -d' ' -f1 | head -c 16)
cp sensitive.pdf ~/secret_clear/(自動加密存入 ~/secret)cat ~/secret_clear/report.txt(自動解密)sudo umount ~/secret_clear(數據變不可讀)# 密鑰簽名緩存(~/.ecryptfs/)
# 掛載參數記錄(/root/.ecryptfsrc 或自定義)
# ⚠️ 遺失密碼/簽名 = 數據永久不可恢復
# /etc/pam.d/login 添加:
auth optional pam_ecryptfs.so unwrap
session optional pam_ecryptfs.so unwrap
/home/user/secret /home/user/secret_clear ecryptfs rw,noauto,user,key=passphrase:passphrase_passwd=Password,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_enable_filename_crypto=y 0 0
modprobe ecryptfs、日誌 dmesg | grep ecryptfsuser 選項eCryptFS 為 Linux 文件級加密提供了強大靈活的解決方案,合理部署可構建堅實的數據隱私防線。