Note: Thanks to the dm_crypt tutorial: http://forums.gentoo.org/viewtopic.php?t=143301 (sorry if I copy some things from there)
But it took me a while to figure out how to setup a loopback file (okay, I'm still n00b) so I thought it would be a good idea to write this short tutorial
The Goal:
Having an encrypted file system which is stored in one file
Introduction
I didn't like the idea of storing all my private files in my home-directory, because you might forget to lock your screen, go away and somebody can take a quick look at them... Beside that, they are stored clearly on the harddisk, so if someone has your harddrive, he has all your private files.
I stumbled over dm_crypt and yeah - that's it! I didn't like cryptoloop, because it seams that it will be replaced soon (http://kerneltrap.org/node/view/2433)
Also I didn't find it useful to encrypt my whole root filesystem - it's quite dangerous and 99% of my system are public available - so why encrypt them? If I have a small (say perhaps 200 MB) file, I can store all my private files and can backup them easily and savely (just burn the encrypted file and even the CIA won't recover your files without the passphrase
Let's start
At first, you need at least a 2.6.4 kernel for device mapping and dm_crypt support. Make sure you have these options enabled:
Device Drivers->Multi-device support (RAID and LVM)->
Code: Select all
[*] Multiple devices driver support (RAID and LVM)
<M> Device mapper support
<M> Crypt target supportCode: Select all
<M> Loopback device supportCode: Select all
<M> AES cipher algorithmsAfter that, you have to create a loopback file. (This will create a 100 MB file at the location /home/secret)
Code: Select all
dd if=/dev/zero of=/home/secret bs=1M count=100Code: Select all
losetup /dev/loop0 /home/secretYou'll need dev-libs/popt, sys-libs/device-mapper, >=dev-libs/libgcrypt-1.1.42 (you'll need an ACCEPT_KEYWORDS="~arch"!) to compile it
Setup the crypt-device:
Code: Select all
modprobe dm_crypt
cryptsetup -c aes -y create secret /dev/loop0So... now your encrypted device is available at /dev/mapper/secret, so let's create a filesystem (I chose ext3):
Code: Select all
mke2fs -j /dev/mapper/secretCode: Select all
mount /dev/mapper/secret /mnt/secretCode: Select all
#/etc/fstab
/dev/mapper/secret /mnt/secret ext3 noauto,noatime 0 0Now you can store your data there and after that just
Code: Select all
umount /mnt/secret
cryptsetup remove secretNext time, you'll only have to type:
Code: Select all
losetup /dev/loop0 /home/secret
cryptsetup create secret /dev/loop0
mount /mnt/secretYou might encrypt your whole /home/user directory, but that has disadvantages: You'll have mounted it all time when you sit in front of your computer, so if you leave it without locking it... then the best encryption is useless!
So I have a separate directory which I mount only when I need it, copy my files there and when I don't need it anymore, I unmount it.
For questions about dm_crypt, look at: http://www.saout.de/misc/dm-crypt/
Hope this tutorial is useful, if I'm wrong somewhere please correct me.




