# Linux Luks Key Management

> Use when managing LUKS key slots, passphrases, recovery keys, and TPM2 enrollments on Linux systems you administer. Covers adding and revoking key slots, rotating passphrases without data loss, backing up and restoring LUKS headers, enrolling and wiping TPM2 and FIDO2 tokens with systemd-cryptenroll, and recovery procedures when a passphrase is lost. Defensive key lifecycle management for encrypted disks, complementing Secure Boot and full-disk encryption deployment.

- Skill: `mizazhaider-ceh/linux-luks-key-management` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/linux-luks-key-management`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/linux-luks-key-management/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/linux-luks-key-management

---


A LUKS volume is only as secure as its key management, and key
management is where encrypted disks are most often lost rather than
broken into. LUKS2 gives you up to 32 key slots, each holding a key
that unlocks the same master key, which means rotation, revocation,
and recovery are slot operations, not re-encryption operations. This
sub-skill covers the slot lifecycle end to end: inspecting slots,
adding and removing keys, rotating without data loss, backing up
headers, enrolling hardware tokens, and recovering when something
goes wrong. The parent skill covers Secure Boot and LUKS deployment
generally; this file is the key management reference.

## Quick Workflow

1. Inspect the current slots with `luksDump` and record which slots
   are enabled before changing anything.
2. Always add the new key before removing the old one, and verify the
   new key unlocks the volume before revoking the old key.
3. Back up the header before any slot operation on a production
   volume, and verify the backup checksum.
4. Rotate on personnel changes, suspected compromise, and schedule
   (at least annually for high-value volumes).
5. Enroll hardware tokens (TPM2, FIDO2) as additional slots, never as
   the only slot: always keep a passphrase slot as fallback.
6. Test recovery quarterly: unlock a test volume with the recovery
   key and from the header backup.
7. Audit slots periodically: an enabled slot you cannot explain is a
   finding, not a mystery to ignore.

## 1. Inspecting key slots

`luksDump` shows the header: format version, cipher, key derivation
function, and every key slot with its state. Read it before any change
and after every change, and keep a copy of the output in the change
record. A slot in state `enabled` accepts its key; a slot in state
`disabled` holds nothing usable. The count of enabled slots should
match your records exactly.

```bash
cryptsetup luksDump /dev/sdX
cryptsetup luksDump /dev/sdX | grep -E "Keyslot|Area|Priority|Key:"
cryptsetup status secure-data
```

Expected on a well-managed volume: LUKS2, Argon2id key derivation,
and a small number of enabled slots (typically a passphrase slot, a
recovery slot, and optionally a TPM2 or FIDO2 slot). If `luksDump`
shows more enabled slots than your records, stop and investigate
before rotating anything: an unknown slot may be an attacker's key,
and removing the wrong slot first could lock out legitimate recovery.

## 2. Adding, changing, and removing keys

Add a key with `luksAddKey` (you must supply an existing key to
authorize the addition), change a passphrase with `luksChangeKey`,
and remove a key with `luksRemoveKey` or by slot number with
`luksKillSlot`. The ordering rule is absolute: add and verify the new
key first, then remove the old one. Removing first and then failing
to add leaves the volume with one fewer way in, and if that was the
last key, the data is gone.

```bash
cryptsetup luksAddKey /dev/sdX
cryptsetup luksChangeKey /dev/sdX
cryptsetup open --test-passphrase /dev/sdX
cryptsetup luksRemoveKey /dev/sdX
cryptsetup luksKillSlot /dev/sdX 3
cryptsetup luksDump /dev/sdX | grep -E "Keyslot|Area"
```

`luksKillSlot` removes by slot number without asking for the key in
that slot, which is the right tool when the key is lost or suspected
compromised, but it is also the most dangerous command in this skill:
killing the wrong slot removes a legitimate way in. Always confirm
the slot number from a fresh `luksDump` immediately before running
it, never from memory or an old printout. After every slot change,
re-run `luksDump` and confirm the slot map matches intent.

## 3. Rotation runbook

Rotation is the scheduled version of the add-then-remove pattern, and
it should be boring. The runbook for a personnel departure or a
suspected key exposure: back up the header, add a fresh passphrase
(or enroll a fresh token), verify the new key unlocks the volume on a
test open, remove the exposed key or kill its slot, verify the old
key no longer unlocks, and update the vault records. Rotation does
not require re-encryption, since the master key never changes, which
is why LUKS rotation is fast even on large volumes.

```bash
cryptsetup luksHeaderBackup /dev/sdX --header-backup-file /root/sdX-header-backup.img
sha256sum /root/sdX-header-backup.img
cryptsetup luksAddKey /dev/sdX
cryptsetup open --test-passphrase /dev/sdX && echo "NEW KEY VERIFIED"
cryptsetup luksKillSlot /dev/sdX 1
cryptsetup open --test-passphrase /dev/sdX
```

The last test-passphrase run is done with the old passphrase and
should now fail; if it succeeds, the old key is still live in another
slot and rotation is incomplete. Record the rotation (date, reason,
slots changed) in the asset record, and rotate the header backup too:
a header backup taken before rotation still contains the old slot,
so an old header plus an old passphrase still unlocks the volume
until the header backup is replaced or destroyed.

## 4. Header backup and restore

The header backup is your insurance against header corruption, which
otherwise destroys the volume regardless of keys. Back it up before
slot operations and after any header change, store it offline with
the same controls as the recovery key, and test restores on a scratch
device. Restoring a header overwrites the current header, including
its slots, so restore only to a copy of the device or when you have
accepted that the current slots will be replaced by the backup's.

```bash
cryptsetup luksHeaderBackup /dev/sdX --header-backup-file /root/sdX-header.img
cryptsetup luksHeaderRestore /dev/sdY --header-backup-file /root/sdX-header.img
cryptsetup luksDump /dev/sdY | head -20
```

Restore to a different device (`/dev/sdY`) for testing, never to the
production device as a test, since a restore to production replaces
the live slot map. Note the security implication in the other
direction: anyone holding a header backup and any one valid key can
unlock the volume, so header backups are key material for storage
and access purposes, not ordinary backups.

## 5. TPM2 and FIDO2 token enrollment

Hardware tokens add a second factor or an unattended unlock path.
TPM2 enrollment seals the key to platform measurements (see the
parent skill for PCR strategy), while FIDO2 enrollment requires a
physical token touch at boot, which suits laptops better than
unattended servers. Enroll with `systemd-cryptenroll`, verify the
slot appears in `luksDump`, test a boot with the token, and keep a
passphrase slot as fallback for both: a lost token or a PCR change
must not become a data-loss event.

```bash
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/sdX
systemd-cryptenroll --fido2-device=auto /dev/sdX
cryptsetup luksDump /dev/sdX | grep -B1 -A3 "systemd-tpm2\|systemd-fido2"
systemd-cryptenroll --wipe-slot=tpm2 /dev/sdX
systemd-cryptenroll --wipe-slot=fido2 /dev/sdX
```

Wipe a token slot when the token is lost, replaced, or decommissioned,
and re-enroll after firmware updates that change TPM2 PCR values.
For FIDO2, record which physical token is enrolled per machine (by
serial, not by "the blue key"), since a fleet of identical tokens
makes the wrong-token-wiped mistake easy.

## 6. Lost passphrase recovery

If every passphrase is lost and no token slot exists, the data is
unrecoverable by design; that is the point of encryption, and no
legitimate recovery path exists beyond the slots you planned. The
planned paths, in order: try the recovery key from the vault, try the
header backup plus a known key (in case the live header is corrupt
but a key survives), and try each enrolled token. Document the
attempts and their outcomes, and if recovery fails, say so plainly
rather than chasing tools that claim to break LUKS: they do not work
against a strong passphrase and Argon2id, and running them wastes
the incident window.

```bash
cryptsetup open --test-passphrase /dev/sdX
cryptsetup luksHeaderRestore /dev/sdY --header-backup-file /root/sdX-header.img
cryptsetup open --test-passphrase /dev/sdY
```

Prevention is the only reliable recovery strategy, which is why this
skill insists on a recovery key in the vault, a tested header backup,
and a passphrase slot alongside every token slot. After any failed
recovery, the post-incident action is to fix the key management
process (vault coverage, rotation schedule, quarterly drills), not to
blame the encryption.

## Edge cases

- `luksKillSlot` by number is dangerous when slot numbers shift after
  earlier operations, so always read a fresh `luksDump` immediately
  before killing a slot and confirm the slot's key material matches
  the key you intend to revoke.
- Header backups taken before a rotation still contain the revoked
  slot, so rotate or destroy old header backups as part of rotation,
  or the revoked key remains usable with the old header.
- Argon2id parameters (time, memory, parallelism) affect unlock speed
  on slow hardware; a volume formatted on a fast machine with high
  memory cost may unlock painfully slowly on an old laptop, so test
  unlock timing on the target hardware class.
- TPM2 PCR values change on firmware and kernel updates, so a TPM2
  slot that worked yesterday can fail after an update; keep the
  passphrase fallback and the re-enrollment step in the update
  runbook.
- FIDO2 tokens with a PIN add a second factor but also a second thing
  to lose; record the PIN handling in the vault procedure, not on a
  note attached to the token.
- LUKS1 volumes (older format) support fewer slots and weaker key
  derivation defaults; migrate LUKS1 volumes to LUKS2 with
  `cryptsetup convert` during a maintenance window rather than
  managing them as if they were LUKS2.
- Multiple administrators adding keys without a shared slot record
  leads to slot sprawl and unknown keys, so treat the slot map as a
  controlled record updated on every change.
- A volume unlocked and mounted is plaintext to root on the live
  system, so key rotation does not retroactively protect data already
  copied off a mounted volume; rotation limits future access, not
  past exposure.

## Key references

- cryptsetup and LUKS documentation: https://gitlab.com/cryptsetup/cryptsetup
- systemd-cryptenroll manual: https://www.freedesktop.org/software/systemd/man/systemd-cryptenroll.html
- cryptsetup FAQ on key management: https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions
- NIST SP 800-111 Guide to Storage Encryption: https://csrc.nist.gov/pubs/sp/800/111/final
- MITRE ATT&CK T1552 Unsecured Credentials (key material): https://attack.mitre.org/techniques/T1552/

