ecryptfs是一種加密文件系統。該文件系統的內容在傳輸和儲存時以密文形式存在。只有在mount時用密鑰解密才能獲得明文。利用這個特性,咱們能夠用他來對軟件鏡像中的部分敏感文件系統進行加密,而後打包發佈。加密
1.加密文件系統
1.1 生成密鑰passphrasespa
sig=`echo none | ecryptfs-add-passphrase | grep -v Passphrase | cut -d[ -f 2 | cut -d] -f 1` echo $sig > sig
1.2 準備空的加密文件系統 fs_cryptcode
mkdir fs_crypt
1.3 將上面建立的加密文件系統mount到加載點blog
mount -t ecryptfs -o ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_passthrough=n,ecryptfs_enable_filename_crypto=n,ecryptfs_sig=${sig},sig=${sig},verbosity=0 /fs_crypt/ /mnt/
1.4 將待加密的文件系統的內容複製到加載點ip
rsync -va /plain/ /mnt/
1.5 將加載點umountci
umount /mnt/
1.6 fs_crypt就是生成的加密文件系統
對fs_crypt壓縮打包,就能夠以密文的形式傳輸和儲存了,
2. 解密文件系統
2.1 將fs_crypt在目標設備上解壓縮
2.2 用passphrase把fs_crypt mount到加載點。it
sig=`cat sig` mount -t ecryptfs -o ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_passthrough=n,ecryptfs_enable_filename_crypto=n,ecryptfs_sig=${sig},sig=${sig},verbosity=0 /fs_crypt/ /mnt/
2.3 訪問加載點裏面的文件便可訪問到明文class
因此這個過程當中,密鑰的保存是很重要的,須要經過其餘加密方式進行分發。打包