How to Encrypt Disks, Partitions and Files With LUKS on Debian

Updated on November 7, 2026

Use guided encrypted LVM to encrypt the system storage during a new Debian installation. For a spare drive or partition, use cryptsetup to create a LUKS2 volume. You can also put files in a LUKS container stored as one file. Choose the method before you format anything.

LUKS disk encryption on Debian Linux

Which LUKS method should you use?

What you want to encrypt Where to start
A new Debian system drive Choose encrypted LVM in the installer. Back up any files on the selected disk first.
A spare disk or data partition Create a LUKS2 volume on an empty partition with cryptsetup.
A group of files you want to store together Create a new encrypted container file and copy your files into it after unlocking it.
A system drive with Debian already installed Back up and verify your files, then reinstall with encrypted LVM if you want a straightforward setup.

LUKS protects data on a locked drive. While it’s unlocked and mounted, users and programs with file permissions can read it. For other ways to protect a Linux drive, see our guide to Linux disk encryption.

Encrypt the system drive when installing Debian

  1. Back up the files you need and verify that you can open them from another drive.
  2. Start the Debian installer. At Partition disks, select Guided – use entire disk and set up encrypted LVM.
  3. Check the drive model and size before accepting any changes. The installer erases the selected disk. Use a strong passphrase you can recover later.
  4. Review the partition layout, finish the installation and reboot. Debian asks for the passphrase before mounting the encrypted system volume.

Guided encrypted LVM puts most system partitions inside the encrypted volume. It creates a separate /boot partition, and an EFI system partition also remains readable on UEFI installations. See the Debian 13 installer guide.

Create a LUKS2 volume on an empty partition

Formatting destroys access to files already on the target. Use an empty partition and work from a verified backup. These steps are for a data volume on an installed Debian system. Stop if you can’t identify the right partition by drive model, size and mount point. The commands use sudo. If you administer Debian from a root shell, run those commands without sudo.

sudo apt update
sudo apt install cryptsetup
lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS,MODEL
ls -l /dev/disk/by-id/

Unmount the target if it’s mounted. Replace the example path with the exact partition you checked. Leave your boot and system partitions alone. Use an unused mapping name if vault_data already exists.

luks_device='/dev/disk/by-id/REPLACE_WITH_VERIFIED_PARTITION'
sudo cryptsetup luksFormat --type luks2 "$luks_device" &&
  sudo cryptsetup open "$luks_device" vault_data

After both commands succeed, create a filesystem on the new unlocked device. Run mkfs.ext4 only for initial setup. Once the volume contains files, skip that command when reopening it.

sudo mkdir /mnt/vault-data &&
  sudo mkfs.ext4 /dev/mapper/vault_data &&
  sudo mount /dev/mapper/vault_data /mnt/vault-data &&
  sudo chown "$(id -u):$(id -g)" /mnt/vault-data

Copy files to /mnt/vault-data and verify that you can open them. Before removing the disk, close any files and unmount it. The second command locks the volume after the first one succeeds.

sudo umount /mnt/vault-data && sudo cryptsetup close vault_data

To use it again, set luks_device to the same partition. Open and mount it without creating another filesystem.

sudo cryptsetup open "$luks_device" vault_data &&
  sudo mount /dev/mapper/vault_data /mnt/vault-data

See Debian’s cryptsetup format reference for the formatting command.

Encrypt files inside a container

A container is a regular file that holds an encrypted volume. From a folder with at least 1 GiB free, create a new file and attach it as a loop device. Run these commands after installing cryptsetup. Keep the filename so you can reopen it later.

vault_file=$(mktemp ./vault.XXXXXX.img) &&
  fallocate -l 1G "$vault_file" &&
  luks_device=$(sudo losetup --find --show "$vault_file") &&
  printf 'Container file: %s\nLoop device: %s\n' "$vault_file" "$luks_device"

If that succeeds, use the LUKS format, open, filesystem and mount steps above with the loop device already assigned to luks_device. Skip the example assignment for the physical partition and use a fresh mount directory if the example is already in use. Copy the files into the mounted container. To finish, unmount it and close the LUKS mapping, then run sudo losetup -d "$luks_device". Next time, attach the same container file to a loop device and use only the open and mount steps.

Back up your data and LUKS header

Keep a verified data backup. A separate LUKS header backup can help if the original header becomes damaged. Use a backup path on a different drive and protect the file. A passphrase that worked when the header was saved can still unlock the encrypted data with that copy, even after you change the live passphrase. See the Debian header backup manual. Replace the backup path below with a location on your separate drive.

sudo cryptsetup luksHeaderBackup --header-backup-file '/path/on/another/drive/vault-header.bin' "$luks_device"

Frequently asked questions

Can I use LUKS without losing existing files?

For the format steps in this guide, first copy your data to a backup, verify it and restore it after creating the encrypted volume. Use an empty partition for the new volume.

Does LUKS encrypt individual files?

LUKS encrypts a volume. To store a few files, create a container, unlock and mount it, then copy the files into it. Lock the container when you finish.

Can I format a USB drive with LUKS?

Yes. Verify the USB device and partition with lsblk, then follow the data volume steps. Keep a separate backup and unlock the drive on a system with LUKS support.

What happens if I forget my passphrase?

You need another valid passphrase or key if you set one up. Keep your recovery information and a separate backup where you can access them.

Does formatting with LUKS erase old unencrypted data securely?

Creating a LUKS header alone doesn’t securely overwrite all the old data blocks. If the drive held sensitive files, plan a separate erase process suited to the drive before reusing or disposing of it.