Using GPG with Custom Homedir | Generated by AI

Home 2025.10

Using GPG’s --homedir Option

The --homedir flag (note: it’s --homedir, not --home-dir—GPG uses a single word) tells GPG to use a custom directory as its “home” for storing configuration files, keyrings, trust databases, and other data. By default, GPG uses ~/.gnupg (e.g., /c/Users/YourName/.gnupg in Git Bash on Windows). This option is useful for:

Basic Syntax

gpg --homedir /path/to/custom/dir [other gpg commands]

Example: Setting Up and Using a Custom Home Directory

  1. Create the custom directory (in Git Bash):
    mkdir -p /c/Users/YourName/my-custom-gpg
    
  2. Generate a keypair using the custom homedir:
    gpg --homedir /c/Users/YourName/my-custom-gpg --full-generate-key
    
    • This stores your keys and config in my-custom-gpg, not the default.
  3. List keys from that directory:
    gpg --homedir /c/Users/YourName/my-custom-gpg --list-secret-keys --keyid-format LONG
    
  4. Encrypt a file using keys from the custom dir:
    gpg --homedir /c/Users/YourName/my-custom-gpg --encrypt --recipient RECIPIENT_EMAIL secret.txt
    
  5. Decrypt a file:
    gpg --homedir /c/Users/YourName/my-custom-gpg --output decrypted.txt --decrypt secret.txt.gpg
    

Tips for Git Bash on Windows

For full details, check the GPG manual: GnuPG Documentation


Back

x-ai/grok-4-fast

Donate