Creating an encrypted filesystem in a file

There are a ton of third party tools for windows that map an encrypted image file to a drive letter (such as Cryptainer LE) so I figured I’d go look around to see how to do it in linux.

http://www.saout.de/tikiwiki/tiki-index.php?page=looptutorial has a great tutorial on how to set this up, but here’s a quick listing of all the commands for the imaptient:

Create and mount an image file

dd if=/dev/zero of=crypt.img bs=1k count=51200
sudo losetup /dev/loop0 crypt.img
sudo cryptsetup -h ripemd160 -c twofish create crypt /dev/loop0
sudo mkreiserfs /dev/mapper/crypt
sudo mount -t reiserfs /dev/mapper/crypt /mnt/moo

This creates a 50MB file, to change this set count to the desired size in kilobytes.

Unmount the image file

sudo umount /mnt/moo
sudo cryptsetup remove crypt
sudo losetup -d /dev/loop0

Remount the image file (For example, after rebooting)

sudo losetup /dev/loop0 crypt.img
sudo cryptsetup -h ripemd160 -c twofish create crypt /dev/loop0
sudo mount -t reiserfs /dev/mapper/crypt /mnt/moo

When you remount cryptsetup will not tell you if the password you entered is the same as the password entered preveously, so if the mount fails you probabally mistyped it. Be carefull because if you write to the image using a different private key (password) you will erase everything in it!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*