How It Works
Age encryption allows you to:- Store encrypted files in your public dotfiles repository
- Decrypt them automatically when applying dotfiles
- Keep your encryption key secure in Bitwarden
Installation
Age is installed during bootstrap:bootstrap.sh:16-18
Key Retrieval and Generation
The bootstrap script handles age key setup automatically:bootstrap.sh:64-79
Process Flow
- Check for existing key: Looks in
~/.config/chezmoi/key.txt - Try Bitwarden: Attempts to retrieve from Secure Note named
chezmoi-age-key - Generate if missing: Creates new key if not in Bitwarden
- Prompt for backup: Displays key content to save in Bitwarden
- Set permissions: Ensures key file is only readable by owner (600)
Chezmoi Configuration
Age encryption is configured in chezmoi’s config:.chezmoi.toml.tmpl:16
.chezmoi.toml.tmpl:45-47
Configuration Details
encryption = "age"- Enables age encryption globallyidentity- Path to your private key for decryptionrecipient- Public key derived from identity for encryption
Encrypting Files
Add Encrypted File to Chezmoi
.age encrypted file in your source directory:
File Naming Convention
encrypted_prefix indicates age encryption.agesuffix marks the file as encrypted.tmplindicates it’s a template (if templating is also used)
encrypted_config.tmpl.age
Encrypted Files in This Repo
SSH Config
Decryption Process
When you runchezmoi apply, encrypted files are:
- Decrypted using your age identity (
~/.config/chezmoi/key.txt) - Processed as templates (if
.tmplsuffix exists) - Written to target location with proper permissions
Security Table
| Secret | Storage | How it’s used |
|---|---|---|
| SSH private key | Bitwarden Secure Note | Pulled via bitwarden template function |
| AWS credentials | Bitwarden Custom Fields | Pulled via bitwardenFields template function |
age private key | Bitwarden Secure Note | Retrieved during bootstrap, stored at ~/.config/chezmoi/key.txt |
| Encrypted files | Git repo (.age) | Decrypted by chezmoi using the age identity |
Manual Age Operations
Encrypt a File
Decrypt a File
View Public Key
Key Rotation
To rotate your age key:-
Generate new key:
-
Re-encrypt all files:
-
Update Bitwarden:
- Save new key as
chezmoi-age-keySecure Note - Delete old key securely
- Save new key as
-
Replace key file:
Best Practices
- Keep your age key in Bitwarden as
chezmoi-age-keySecure Note - Never commit unencrypted
key.txtto git - Set restrictive permissions (600) on the key file
- Encrypt any file containing secrets before adding to chezmoi
- Test decryption on new machines to ensure key backup works
Troubleshooting
Decryption Failed
Ifchezmoi apply fails with decryption errors: