Linux encryption - encrypted directories

I've always been fond of storing a directory structure encrypted in a file (ala TrueCrypt or PGPDisk). I borrowed instructions from here.

Create the raw file to contain your encrypted data.

dd if=/dev/urandom of=~/encrypted.bin bs=1M count=100

Find the next available loop device and map this file to it.

losetup -f
losetup /dev/loop0 ~/encrypted.bin

Setup the crypto filesystem, open it with the correct password, format the partition ext3, and finally mount the newly created filesystem as /mnt/tmp

cryptsetup --verbose --cipher "aes-cbc-essiv:sha256" --key-size 256 --verify-passphrase luksFormat /dev/loop0
cryptsetup luksOpen /dev/loop0 my-crypt
mkfs.ext3 /dev/mapper/my-crypt
mount -t ext3 -o rw,defaults /dev/mapper/my-crypt /mnt/tmp/

When you're all done, and want to secure all the files do the following. Umount the filesystem, close the crypto link, remove the file to loopback device link.

umount /mnt/tmp/
cryptsetup luksClose my-crypt
losetup -d /dev/loop0
Leave A Reply - 1 Reply
Replies
Gene 2008-09-22 02:13pm - gene@aquamd.com - Logged IP: 67.189.135.124

Scott, I came across your comic directory, i.e. http://www.perturb.org/comics/ and thought you might enjoy adding this one to your list: www.PublicWorksComics.com I always get a kick out of them.

All content licensed under the Creative Commons License