eCryptfs的安裝
Debian,Ubuntu或其衍生版:
$ sudo apt-get install ecryptfs-utils
CentOS, RHEL or Fedora:
$ yum install ecryptfs-utils
Arch Linux:
$ sudo pacman -S ecryptfs-utils
使用eCryptfs
1.mount 需要root權限,我們使用 命令sudo ,來以root身份運行命令
結果如下:
passphrase:
(這是要你輸入密碼,自己編一個。一定要記住。另外密碼是不會有任何顯示的,輸完回車就行)
select cipher:
(選擇加密方式,不選默認是[aes]。最好記住自己的選擇)
select key bytes:
(選擇加密位數,不選默認是[16]。最好記住自己的選擇)
enable plaintext passthrough(y/n) [n]:
(是否允許使用明文,默認是 n)
enable filename encryption (y/n) [n]:
(是否把文件名也進行加密,默認是 n。如果選擇y,那么在沒有解密 的情況下是無法看見文件夾內部的文件的)
如果設置的密碼是第一次使用,它會提示你密碼被標識為[799d2f922c0f1f26] 。當然,你的密碼標識肯定不會是這個。並且告訴你掛載錯誤,因為/root/.ecryptfs/sig-cache.txt中沒有相關記錄。開始讓你選擇:
Would you like to proceed with the mount (yes/no)? :
(你是否希望繼續進行掛載。我們輸入yes,來完成加密)
Would you like to append sig [799d2f922c0f1f26] to
[/root/.ecryptfs/sig-cache.txt]
in order to avoid this warning in the future (yes/no)?:
(你是否把密碼標識加到/root/.ecryptfs/sig-cache.txt中,免得下次再報警。我們輸入yes)
如圖:

2.好了,現在正常操作ecryptfs_test文件夾。
放一些文件來測試。
3.關閉解密
命令:
$ sudo umount -t ecryptfs ecryptfs_test
(如果使用的是sudo mount -t ecryptfs real_path ecryptfs_mounted_path
那么對應的命令是sudo umount -t ecryptfs ecryptfs_mounted_path)
這命令是把掛載取消了。這里的作用相當於把解密取消了,畢竟把重要文件長時間解密放着不好。
好了,再看看ecryptfs_test文件夾,里面的文件是不是都無法正確打開了?
需要解密文件夾時還是用命令:
$ sudo mount -t ecryptfs ecryptfs_test ecryptfs_test
(格式還是不變:sudo mount -t ecryptfs real_path ecryptfs_mounted_path)
passphrase:
select cipher:
select key bytes:
enable plaintext passthrough(y/n) [n]:
enable filename encryption (y/n) [n]:
上面這幾相當初怎么設置的就怎么填,之后文件夾就解密了。
不用了,還是用命令解除解密狀態
$ sudo umount -t ecryptfs ecryptfs_test
這里說一點,mount命令重啟就失效了。如果你要關機了,不必使用
$ sudo umount -t ecryptfs ecryptfs_test
命令了。因為再次開機,解密是失效的。必須重新運行命令
$ sudo mount -t ecryptfs ecryptfs_test ecryptfs_test
如圖,d2文件夾內自動加解密,d1處文件為密文


