Encrypted LUKS Container

Create an encrypted volume on linux using LUKS

Problem

This page describes how to create an encrypted container on a #linux system using LUKS.

*This is not the same as on-the-fly encryption

Solution

The only software required for this process is cryptsetup. It can be installed with apt:

apt install cryptsetup

All the following commands should be run as root

  1. Create file
fallocate -l 25G /enc

Change the size of the file as necessary. This will determine the available drive space when mounted.

  1. Create LUKS container
cryptsetup luksFormat /enc

Follow the prompts in the command line - including the passphrase to unlock the container.

  1. Setup filesystem
cryptsetup luksOpen /enc enc
mkfs.ext4 /dev/mapper/enc

Once the container has been setup, the root user can mount it with the following commands.

  1. Open container
cryptsetup luksOpen /enc enc

You will be prompted for the passphrase used when creating the volume.

  1. Mount container
mount /dev/mapper/enc /data

Details