Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

4.4.1. Encryption at Rest: LUKS2 and GPG

💡 First Principle: Encryption at rest protects data when the storage medium is physically accessible — a stolen laptop, a decommissioned disk, a compromised backup. Without it, any physical access to the disk bypasses all Linux permission controls. With full disk encryption, the disk's data is unreadable without the passphrase, regardless of which OS boots from it.

LUKS2 — Linux Unified Key Setup:

LUKS2 is the standard full-disk/partition encryption layer for Linux. It sits between the block device and the filesystem — the kernel decrypts blocks on read and encrypts on write, transparently to the filesystem above.

# Encrypt a partition (destructive — data is lost)
cryptsetup luksFormat --type luks2 /dev/sdb1      # Create LUKS2 container
cryptsetup luksOpen /dev/sdb1 encrypted_data       # Open → /dev/mapper/encrypted_data
mkfs.ext4 /dev/mapper/encrypted_data              # Format the decrypted device
mount /dev/mapper/encrypted_data /mnt/secure      # Mount normally

# Close (unmount first)
umount /mnt/secure
cryptsetup luksClose encrypted_data

# Key management
cryptsetup luksDump /dev/sdb1                     # Show LUKS header info
cryptsetup luksAddKey /dev/sdb1                   # Add additional key slot
cryptsetup luksRemoveKey /dev/sdb1                # Remove a key slot
cryptsetup luksChangeKey /dev/sdb1                # Change passphrase

# Cryptographic destruction (wipe LUKS header → data permanently inaccessible)
cryptsetup luksErase /dev/sdb1                    # Wipe all key slots
LUKS2 Enhancements over LUKS1:
  • Argon2id key derivation (memory-hard — resistant to GPU brute-force attacks)
  • Larger header with metadata area
  • Online reencryption support
GPG — GNU Privacy Guard (File Encryption):

GPG implements OpenPGP for file-level encryption and signing. Where LUKS encrypts entire block devices, GPG encrypts individual files.

# Symmetric encryption (password-based)
gpg -c sensitive.tar.gz                    # Encrypt with passphrase → sensitive.tar.gz.gpg
gpg -d -o sensitive.tar.gz sensitive.tar.gz.gpg  # Decrypt to file (without -o, output goes to stdout)

# Asymmetric encryption (key-based)
gpg --gen-key                             # Generate key pair
gpg --list-keys                           # List public keys
gpg --list-secret-keys                    # List private keys
gpg --export -a "alice@example.com" > alice.pub   # Export public key
gpg --import bob.pub                      # Import someone's public key
gpg -e -r "bob@example.com" file.txt     # Encrypt for bob (using his public key)
gpg -d file.txt.gpg                       # Decrypt (using your private key)

# Signing
gpg --sign file.txt                       # Sign file (creates file.txt.gpg)
gpg --verify file.txt.gpg                 # Verify signature

⚠️ Exam Trap: LUKS encrypts at the block layer — the filesystem has no knowledge of encryption. This means fsck, resize2fs, and other filesystem tools operate on the decrypted device (/dev/mapper/name), not the raw encrypted partition. Attempting to run fsck /dev/sdb1 on an encrypted partition without opening it first will corrupt the LUKS header.

Reflection Question: A hard drive containing sensitive data must be decommissioned. The data is on a LUKS2-encrypted partition. What is the fastest and most secure way to ensure the data is irrecoverable, and why is it more effective than overwriting with random data?

Alvin Varughese
Written byAlvin Varughese
Founder18 professional certifications