Donnerstag, 18. Februar 2010

howto encrypt a directory to a file

To encrypt a directory input_directory to a encrypted file do the following:

a) generated a file input_directory_file big enough to hold the data. This file will be the
filename of theencrypted file later. To do this you can use the command dd if=/dev/zero
of=input_directory_file bs=1M count=100. This command will generate a file with 100Mb size.
b) losetup /dev/loop0 input_directory_file
c) cryptsetup luksFormat /dev/loop0 (answer with YES and specify the password twice)
d) cryptsetup luksOpen /dev/loop0 containername
e) mke2fs /dev/mapper/containername (to put a filessystem to the device)
f) mkdir container_dirctory
g) mount /dev/mapper/containername container_directory
h) put all the files and directories inside this container_directory
i) umount container_directory
j) cryptsetup luksClose containername
k) losetup -d /dev/loop0

That's all