Difficulty: Easy
Estimated Time: 15-20 minutes

In this tutorial we will see how to create and use an encrypted archive with cryptsetup. This might be useful if you keep personal data on a movable device (for example a USB stick), which might be lost or accessed by unauthorized people. In this case they won't be able to look at your personal data without knowing the password.

Encrypted Archive with Cryptsetup

Step 1 of 5

Step 1

Create the archive

  1. Make sure that cryptsetup is installed:

    apt list cryptsetup

    apt install cryptsetup

  2. Create an image file for the archive:

    fallocate -l 15G archive1.img

    ls -lh

    However, to make sure that the created file has random data, you can use a command like this (which is slower):

    dd if=/dev/urandom of=archive1.img bs=10M count=100

    This would increase the encryption strength, since an attacker can't distinguish the part of the archive that is free from the part that has encrypted data.

  3. Create a loop device for this image file:

    losetup -f archive1.img

    losetup -a

    losetup -a | grep archive1.img


    lsblk | grep loop