vault — Encrypted .env Backup
vault is a centralized encrypted backup manager for
.env files across all your projects. It uses
SOPS (Secrets OPerationS) with GPG encryption
to securely store environment variables in a central
location at ~/Git/dotenvs/.
How It Works
Section titled “How It Works”- Central Storage — All encrypted backups live in
~/Git/dotenvs/ - Project-based — Each project’s
.envfile is backed up with the project directory name (e.g.,myproject.env.encrypt) - GPG Encryption — Uses your GPG key to encrypt and decrypt files
- Smart Sync — Automatically detects which version is newer and syncs accordingly
- Safety First — Always creates timestamped backups before overwriting
Requirements
Section titled “Requirements”Before using vault, ensure you have:
- A GPG key configured on your system
- SOPS installed (
brew install sopson macOS)
Commands
Section titled “Commands”vault sync
Section titled “vault sync”Smart synchronization that automatically detects the sync direction:
- If only local
.envexists, encrypts to vault - If only vault backup exists, decrypts to local
- If local is newer, encrypts to vault (with confirmation)
- If vault is newer, decrypts to local (with confirmation)
vault sync # Auto-detect directionvault sync --push # Force local -> vaultvault sync --pull # Force vault -> localvault encrypt
Section titled “vault encrypt”Explicitly encrypt your local .env file to the
centralized vault:
vault encryptFeatures:
- Creates a timestamped backup if the encrypted file already exists
- Requires confirmation before overwriting existing backups
vault decrypt
Section titled “vault decrypt”Explicitly decrypt from the centralized vault to
your local .env:
vault decryptFeatures:
- Creates a timestamped backup of the current
.envbefore overwriting - Warns if the local
.envis newer than the backup - Requires confirmation in case of conflicts
vault list
Section titled “vault list”List all encrypted backups in the central vault:
vault listShows all .env.encrypt files in
~/Git/dotenvs/ with their sizes.
vault status
Section titled “vault status”Show detailed sync status for the current project:
vault statusDisplays:
- Whether the local
.envexists - Whether a backup exists in the vault
- Which version is newer (with timestamps)
- Sync status (in sync, local newer, backup newer, etc.)
Workflow Examples
Section titled “Workflow Examples”Initial Setup
Section titled “Initial Setup”-
Navigate to your project directory:
Terminal window cd myproject -
Create your
.envfile with the required secrets. -
Back up to the central vault:
Terminal window vault encrypt
Cloning a Project
Section titled “Cloning a Project”-
Clone the repository:
Terminal window git clone https://github.com/user/projectcd project -
Restore
.envfrom the central vault:Terminal window vault decrypt
Regular Development
Section titled “Regular Development”-
After modifying your
.envfile, sync to vault:Terminal window vault sync # Automatically encrypts to vault -
On a different machine, pull the latest:
Terminal window vault sync # Automatically decrypts newer version
Conflict Resolution
Section titled “Conflict Resolution”When both local and vault versions exist but differ:
-
Check which version is newer:
Terminal window vault status -
Force the direction you want:
Terminal window vault sync --push # Force local -> vaultvault sync --pull # Force vault -> local
Security Notes
Section titled “Security Notes”- Files are encrypted using your GPG key
- Only you can decrypt the files (with your private key)
- Encrypted files are safe to store in version control
- Timestamped backups protect against accidental overwrites
Troubleshooting
Section titled “Troubleshooting””No GPG key found”
Section titled “”No GPG key found””Generate a GPG key:
gpg --gen-keyFollow the prompts to create a new key pair. Once
created, vault will automatically detect and use it.
”SOPS not found”
Section titled “”SOPS not found””Install SOPS for your platform:
brew install sopsDownload the latest release from the SOPS releases page.
Permission Issues
Section titled “Permission Issues”Ensure you have write access to the vault directory:
mkdir -p ~/Git/dotenvschmod 700 ~/Git/dotenvsThe 700 permission ensures only your user can read,
write, or list the directory contents.