Skip to content

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/.

  1. Central Storage — All encrypted backups live in ~/Git/dotenvs/
  2. Project-based — Each project’s .env file is backed up with the project directory name (e.g., myproject.env.encrypt)
  3. GPG Encryption — Uses your GPG key to encrypt and decrypt files
  4. Smart Sync — Automatically detects which version is newer and syncs accordingly
  5. Safety First — Always creates timestamped backups before overwriting

Before using vault, ensure you have:

  • A GPG key configured on your system
  • SOPS installed (brew install sops on macOS)

Smart synchronization that automatically detects the sync direction:

  • If only local .env exists, 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)
Terminal window
vault sync # Auto-detect direction
vault sync --push # Force local -> vault
vault sync --pull # Force vault -> local
  1. Navigate to your project directory:

    Terminal window
    cd myproject
  2. Create your .env file with the required secrets.

  3. Back up to the central vault:

    Terminal window
    vault encrypt
  1. Clone the repository:

    Terminal window
    git clone https://github.com/user/project
    cd project
  2. Restore .env from the central vault:

    Terminal window
    vault decrypt
  1. After modifying your .env file, sync to vault:

    Terminal window
    vault sync # Automatically encrypts to vault
  2. On a different machine, pull the latest:

    Terminal window
    vault sync # Automatically decrypts newer version

When both local and vault versions exist but differ:

  1. Check which version is newer:

    Terminal window
    vault status
  2. Force the direction you want:

    Terminal window
    vault sync --push # Force local -> vault
    vault sync --pull # Force vault -> local
  • 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

Generate a GPG key:

Terminal window
gpg --gen-key

Follow the prompts to create a new key pair. Once created, vault will automatically detect and use it.

Install SOPS for your platform:

Terminal window
brew install sops

Ensure you have write access to the vault directory:

Terminal window
mkdir -p ~/Git/dotenvs
chmod 700 ~/Git/dotenvs

The 700 permission ensures only your user can read, write, or list the directory contents.