Skip to main content
RunBook Academy

LinuxXLVII · Backup StrategyEncryption keys

Encryption and key management - protecting backups at rest

Advanced⏱ ~10 minborgagesops

What you'll learn

  • Encrypt backups at rest
  • Manage encryption keys
  • Recover keys in DR
  • Avoid the key-loss trap

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

Backups often contain sensitive data. Encryption protects them at rest, but key management is the discipline that keeps them recoverable.

Encrypt backups at rest

Tools:

  • BorgBackup: client-side encryption with AES-OCB.
  • age: modern encryption tool.
  • openssl enc: standard tool for symmetric encryption.
  • gpg: PGP encryption.

BorgBackup example:

# Init with encryption
borg init --encryption repokey-blake2 /backup/repo

# Create encrypted backup
borg create /backup/repo::backup-2026-08-09 /var/data

# Borg automatically encrypts before sending to /backup/repo

The encryption key is derived from the passphrase. Lose the passphrase, lose the backups.

Key management

Keys must be:

  • Backed up: at least 2 independent copies.
  • Access-controlled: only key custodians can read.
  • Versioned: when rotated, old keys are kept (until decryptions of old backups are no longer needed).
  • Audited: who accesses the key, when.

Storage options:

  • Vault (HashiCorp, AWS KMS, GCP Secret Manager): managed secret storage.
  • Hardware security module (HSM): physical device.
  • Paper backup in safe: for the most critical keys.
  • Multi-person: split the key across multiple people.

For a single key:

# Generate a strong passphrase
openssl rand -base64 32 > /etc/borg/passphrase
chmod 600 /etc/borg/passphrase

# Backup the passphrase
gpg --encrypt --recipient ops@example.com /etc/borg/passphrase
# Or store in vault

Key recovery in DR

If you cannot find the key, you cannot decrypt the backups. The DR plan must include key recovery.

DR procedure:
1. Find the vault operator.
2. Retrieve the key from the vault.
3. Decrypt the passphrase file.
4. Use the passphrase to unlock BorgBackup.
5. Restore data.

Test this. A DR plan that has not been tested is a hope.

Rotation

Rotate keys periodically:

  • Quarterly for high-value keys.
  • Annually for standard keys.
  • Immediately on personnel change.

When you rotate:

  • Old key is kept until old backups are no longer needed.
  • New key is used for new backups.
  • Document the rotation in the key log.

Knowledge check

Knowledge check · 3 questions

  1. Q1. What is the best practice for encryption keys in backups?

  2. Q2. Losing the encryption key means losing the backup.

  3. Q3. Which of the following are valid encryption tools for backups? Select all that apply.

Passing score: 75%. Answers are checked in this browser.