Recipes
Four complete jobs, assembled from chapters you have already read. The lab ran every cryptsetup step in them except the device-mapper ones of chapter 5; the transcripts are the evidence, recipe by recipe.
1. Encrypt a USB stick, end to end
The canonical job. Identify the stick
by UUID and size, never by today's
device letter — lsblk first, and
read its output like the device is
trying to trick you, because one day
the wrong line will look very
convincing.
sudo cryptsetup luksFormat --type luks2 /dev/disk/by-id/<your-stick>
sudo cryptsetup open /dev/disk/by-id/<your-stick> stick
sudo mkfs.ext4 /dev/mapper/stick
sudo cryptsetup luksHeaderBackup /dev/disk/by-id/<your-stick> \
--header-backup-file stick-header.bak
Then mount, use, and put away with chapter 5's verbs. The header backup goes home to your password manager or an encrypted folder — not onto the stick. From here the stick is a citizen: it can grow slots (chapter 6), take a label (chapter 12), and be added to a machine's crypttab if it lives a docked life (chapter 9).
2. Add a spare passphrase before a trip
The cheapest insurance in this guide, bought in two minutes (t02):
cryptsetup luksAddKey --key-file <main-pass-file> <device>
cryptsetup open --test-passphrase <device> # with the NEW passphrase
cryptsetup luksHeaderBackup <device> --header-backup-file <fresh.bak>
Write the spare down and store it away from the machine — a sealed envelope at home, a relative's safe, your password manager's notes. Prove it works before you need it (the test above, today, not at an airport), and take the fresh header backup in the same sitting, because chapter 8's rule admits no exceptions: slot changes and backups travel together.
3. Rotate a passphrase
Someone saw it typed; it was reused somewhere that leaked; it is simply old. Rotation is add-prove-kill (chapter 6), in that order, with no step skippable:
cryptsetup luksAddKey <device> # the new passphrase joins
cryptsetup open --test-passphrase <device> # prove the new one
cryptsetup luksRemoveKey <device> # retire the old one, by identity
cryptsetup luksHeaderBackup <device> --header-backup-file <fresh.bak>
The data never re-encrypts, the master key never changes, and at no moment does the vault depend on a passphrase you have not just proven. If the master key itself is the suspect — not a passphrase — that is chapter 12's reencrypt conversation, and probably a restore-from-backup conversation instead.
4. Wipe a device so nothing comes back
Selling, recycling, or retiring a disk that held ciphertext: you do not need to overwrite terabytes. The data is only as reachable as its keyslots, so destroying them is destroying the data — the lab proved the principle in t12:
cryptsetup erase <device>
Afterwards the header still describes
a LUKS device — isLuks still
answers yes — but every test answers
No usable keyslot is available., and
the data segment is noise to everyone,
forever, in well under a second of
work. Three qualifications, all of
them chapter 8 in a trench coat: this
works because the slots held the only
copies of the master key; a header
backup kept elsewhere un-wipes the
device completely, so wipe your
backups of it too; and on flash media,
where old bytes can linger in retired
cells, the cautious still overwrite
the header area itself
(dd if=/dev/urandom over the first
32 MB covers both LUKS generations
with room to spare) or use the drive
maker's secure-erase. Then let it go
with a clear conscience.