Encrypted Archive with Cryptsetup

Table of Contents

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.

2 Format the archive

Using the cryptsetup command, format the drive with Linux Unified
Key Setup (LUKS):

cryptsetup luksFormat /dev/loop0

LUKS stores some metadata at the beginning of the partition
regarding the type of encryption used and the encryption key. The
key is randomly generated but is itself encrypted using a
passphrase that you provide. The passphrase should be at least 3
random words.

Create a virtual device using cryptsetup that encrypts and decrypts
all data going to and from the loop device: