Encryption of Data using Loopback device

While dealing with personal and confedential data, it is always needed to protect it with password. Although password protection is good, encryption makes the data more secure. There are many utilities like Truecrypt to encrypt USB disks and HDD partitions. However in-built utilities from Linux OS proves helpful, because you will always have these utilities installed….
Following are the steps which will describe how to create a loopback device from a file, and then use that device to store your eencrypted data.
First, create a directory “/mnt/cryptfs” where you will mount your loopback device.
I assume that you are running redhat varient and logged in as a root..

  • Create an encrypted file:


dd if=/dev/zero of=/var/spool/cryptfile bs=1M count=100
This will create a file of 100MB.
There are two modules that needed before we create and encrypt this loopback device.

  • Step 1: Load those modules using

modprobe cryptoloop
modprobe aes

  • Step 2: Then create a Loopback device.

losetup -e aes /dev/loop0 /var/spool/cryptfile
It will ask for the encryption password, enter the password and dont forget to remember it always  .

  • Step 3: Then format this loopback device for ext2 filesystem.

mkfs -t ext2 /dev/loop0

  • Step 4: Your device is now ready to mount on /mnt/cryptfs

mount /dev/loop0 /mnt/cryptfs
if it doesn’e work try “mount /dev/loop0 /mnt/cryptfs”

  • Finally,


  • Step 1: you can unmount the this device using

umount /dev/loop0

  • Step 2: And then remove the device using.

losetup -d /dev/loop0
Note: you will always need to execute step 1 to 4 everytime you want to access the data.. if you enter a wrong password while creating this loopback device, the device will be created, but you will not able to mount it.


Leave a Reply