Encryption is the last line of defense of a backup: without the correct key or passphrase, the repository is unreadable. This episode dissects the repokey, keyfile, and authenticated modes, teaches key export and import, and the strategies for storing the passphrase and keyfile so you do not lock yourself out of your own data.

In episode 3 you chose the encryption mode during borg init. Now we dissect that encryption fully: what is actually secured, where the key is stored, and how to manage the key so you never lose access. Remember the principle from episode 2: without the key, the repository is unreadable — even by you. This section is the one that most determines the fate of your data.
In repokey mode, the encryption key is stored inside the repository and protected by a passphrase. The advantage is practical: no separate file to protect. The risk: anyone who steals the repository and manages to guess the passphrase can read the data. A strong, unique passphrase is non-negotiable.
In keyfile mode, the key is stored in a separate file (usually ~/.config/borg/keys/). A repository thief does not take the key with them — an extra security layer. The consequence is clear: the key file must be backed up. Losing the keyfile means losing access to all backups, even if you still remember the passphrase.
authenticated mode does not encrypt the data (making it readable on the server) but still verifies integrity. It is suitable when the storage is already encrypted at a lower layer (ZFS encryption, LUKS, encrypted cloud volumes) and you want to avoid CPU overhead. By contrast, none mode provides no security at all — only for experiments.
+----------------+-----------+-----------+-----------------------+
| Mode | Encryption| Integrity | Key stored in |
+----------------+-----------+-----------+-----------------------+
| repokey-blake2 | yes | yes | repository (passphrase)|
| keyfile-blake2 | yes | yes | separate file |
| authenticated | no | yes | - |
| none | no | no | - |
+----------------+-----------+-----------+-----------------------+Warning
The encryption mode is set during borg init and cannot be changed without creating a new repository. The safest choice for production: repokey-blake2 with a strong passphrase, or keyfile-blake2 with the key file backed up somewhere separate.
Borg provides borg key export to make a copy of the key:
borg key export /backup/borg /root/borg-key-backup.txtborg key export --paper /backup/borg--paper produces a base64 format that can be printed and stored in a separate physical location. Keep the export result somewhere different from the repository — the same principle as 3-2-1 for data.
If the key goes missing from its original location, import it from the backup:
borg key import /backup/borg /root/borg-key-backup.txtThe passphrase can be changed at any time without touching the data (the key is re-encrypted):
borg key change-passphrase /backup/borgSince episode 3 we have used BORG_PASSCOMMAND. This is also the doorway into secret management:
export BORG_PASSCOMMAND='pass show backup/borg'export BORG_PASSCOMMAND='cat /root/.borg-passphrase'With this pattern, the passphrase never appears in history, in ps, or in logs — it is only read when needed.
Warning
There is no "forgot your passphrase? it can be reset" in Borg. There is no backdoor. If the passphrase is lost, the only way out is restoring from the key backup (borg key export) — which is exactly why exporting the key should be part of the setup ritual, not a "later" thing.
borg list from a clean environment to confirm access works.borg key export, including --paper) is mandatory insurance.borg key import and borg key change-passphrase for recovery and rotation.BORG_PASSCOMMAND.In episode 8 we manage history: prune & compact (retention) — deleting old archives measurably with borg prune, reclaiming space with borg compact, building a retention policy that fits your RPO/RTO, and using --keep-tag for tagged archives.