How To Encrypt Directories/Partitions With eCryptfs On Debian Squeeze
|
Submitted by falko (Contact Author) (Forums) on Sun, 2011-07-24 18:12. :: Debian | Security | Storage
How To Encrypt Directories/Partitions With eCryptfs On Debian SqueezeVersion 1.0 eCryptfs is a POSIX-compliant enterprise-class stacked cryptographic filesystem for Linux. You can use it to encrypt partitions and also directories that don't use a partition of their own, no matter the underlying filesystem, partition type, etc. This tutorial shows how to use eCryptfs to encrypt a directory on Debian Squeeze. I do not issue any guarantee that this will work for you!
1 Preliminary NoteIn this tutorial I will encrypt my home directory, /home/falko/, which is located on the / partition (i.e., /home/falko/ is an ordinary directory and does not use a partition of its own).
2 Installing eCryptfseCryptfs can easily be installed as follows: apt-get install ecryptfs-utils
3 Encrypting A DirectoryI will now encrypt my home directory /home/falko/. As there are already (unencrypted) files in that directory, I must take a backup of them so that I can restore them to the then encrypted /home/falko/ directory later on (otherwise these filles cannot be accessed/read while the directory is encrypted): cp -pfr /home/falko/ /tmp/ I can now encrypt the directory /home/falko/ by mounting it with the file system type ecryptfs: mount -t ecryptfs /home/falko /home/falko When you do this for the first time, you will have to answer a few questions: root@server1:~# mount -t ecryptfs /home/falko /home/falko Take a look at the output of mount and you should see that /home/falko/ is now encrypted: root@server1:~# mount Let's restore our backup to the now encrypted directory /home/falko/ and delete the backup afterwards: cp -pfr /tmp/falko/ /home/ For testing purposes, let's copy some other file, e.g. /etc/hosts, to /home/falko/ to check if it really gets encrypted: cp /etc/hosts /home/falko While /home/falko/ is mounted with the ecryptfs file system type, it should be possible to read the contents of /home/falko/hosts: cat /home/falko/hosts Now unmount /home/falko/... umount /home/falko ... and try again to read /home/falko/hosts, and you should get some cryptic stuff: cat /home/falko/hosts
4 How To Automatically Mount An Encrypted Partiton At Boot TimeOf course, we don't want to mount /home/falko/ manually each time - it would be nicer if could be mounted automatically at boot time. To do this we need a passphrase file, and for security reasons I want this passphrase file to be located on a USB key. Plug in a USB key and run fdisk -l to find out its device name and file system type: root@server1:~# fdisk -l In my case the device name is /dev/sdb1, and it uses a FAT32 file system. Let's mount the USB key to /mnt/usb: mkdir /mnt/usb Take a look at the output of mount ... and you should see that it got mounted with the file system type vfat (FAT32) - we will need this information later on for our /etc/fstab file: root@server1:~# mount Now take a look at the contents of /root/.ecryptfs/sig-cache.txt: cat /root/.ecryptfs/sig-cache.txt
We need this signature for the file /root/.ecryptfsrc which we create as follows: vi /root/.ecryptfsrc Please make sure that you use the signature from the /root/.ecryptfs/sig-cache.txt file in the ecryptfs_sig line:
Now we create the passphrase file on our USB key: vi /mnt/usb/passwd_file.txt
Make sure that you use the correct passphrase, i.e., the passphrase that you would use if you mounted the directory manually. Next open /etc/fstab... vi /etc/fstab ... and add the following two lines (make sure you use the correct file system type for your USB key - vfat in my case):
(It is important the the line for the USB key comes before the line for the encrypted partition because the USB key needs to be mounted before the encrypted partition can be mounted!) Then reboot the system: reboot If everything goes fine, your encrypted partition should automatically be mounted after the reboot. However, it is possible that your system cannot mount your USB key during boot, which means your encrypted partition cannot be mounted either. If this happens, edit /etc/rc.local (this script is executed at the end of the boot process)... vi /etc/rc.local ... and add the line /bin/mount -a before the exit 0 line:
This will (re-)mount all partitions (including your USB key and the encrypted partition) at the end of the boot process.
5 Links
|




Recent comments
1 day 3 hours ago
1 day 8 hours ago
1 day 10 hours ago
1 day 10 hours ago
1 day 12 hours ago
1 day 17 hours ago
1 day 17 hours ago
1 day 20 hours ago
2 days 9 hours ago
2 days 10 hours ago