Course contentsShow
← Linux
Lesson 654 of 1,8197. Storage Management and Logical VolumesFree lesson

Key management for encrypted volumes

Implement key files and passphrase rotation policies for encrypted storage.

In this lesson, you will learn how to enhance the security of encrypted volumes by implementing key files and establishing rotation policies for your passphrases.

When you encrypt a block device (like a partition using LUKS), the volume is typically opened by entering a passphrase. However, relying solely on a human-entered passphrase can be risky or inconvenient, especially for automated systems. This is where key files and passphrase rotation come in.

Using Key Files

A key file is simply a file containing random data that acts as a physical "key" to unlock your volume. Instead of typing a password, the system reads the file to derive the master key. This is useful for headless servers or automated booting where you store the key file on a secure secondary device (like a USB stick).

To add a key file to an existing encrypted volume, you use the cryptsetup command:

# Add a key file as a new slot
sudo cryptsetup luksAddKey /dev/sdb1 /path/to/secret_keyfile

By keeping the key file on an external, removable drive, you ensure that the encrypted volume cannot be mounted unless the physical key is present.

Passphrase Rotation Policies

Security best practices dictate that passphrases should be changed periodically to limit the impact if a passphrase is ever intercepted or guessed. Because LUKS supports multiple "slots" (typically 8), you can rotate your keys without losing access to your data.

  1. Add a new passphrase: Add your new, secure passphrase into an empty slot using luksAddKey.
  2. Verify: Test the new passphrase by attempting to open the volume with it.
  3. Remove the old passphrase: Once the new one works, you can safely remove the old slot to ensure the compromised or outdated password no longer grants access:
# Remove an old passphrase by identifying its slot number
sudo cryptsetup luksRemoveKey /dev/sdb1

By maintaining multiple slots, you ensure that even if a rotation fails or you forget a password, you have a fallback mechanism to prevent data lockout.

Key Takeaway: Use key files to automate secure mounting, and leverage LUKS key slots to rotate credentials regularly without risking data availability.