How to Create an Encrypted Container with LUKS
sudo apt install -y cryptsetup
Create a container
In this example we’ll create a 1GB file called
vault.img. Adjust to your needs.
fallocate -l 1GB vault.img
Encrypt the container with LUKS
cryptsetup -v luksFormat vault.img
Open the encrypted drive
vault as the handle. Change to your liking.
cryptsetup luksOpen vault.img vault
Create an ext4 filesystem
vault as the label. Change to your liking.
sudo mkfs.ext4 /dev/mapper/vault -L vault
Mount the encrypted drive
/mnt/vault as the mount point. Change to your liking.
sudo mount /dev/mapper/vault /mnt/vault
Unmount everything if you wish
sudo umount /mnt/vault && sudo cryptsetup luksClose vault