This guide provides a comprehensive, “terminal-first” approach to setting up robust end-to-end email encryption. By creating your cryptographic keys directly with GnuPG, you build a universal and secure foundation. We will then show you how to integrate this setup seamlessly with both Thunderbird, a user-friendly graphical client, and Neomutt, a powerful terminal-based client.

Changelog

DateChange
2026-10-16Fix passphrase caching, terminal prompts, Thunderbird storage, and key transfer.
2025-07-15Major Restructure (Terminal-First): The entire guide was rewritten to prioritize key creation in the terminal (gpg), making it more robust, universal, and secure. This resolves platform-specific client issues.
2025-07-15Initial Version: Article created.

1. Pre-Flight Check – Your System’s Foundation

Before we create any keys, we must ensure your system is correctly configured.

1.1. Install GnuPG

This is the core encryption engine.

  • Debian/Ubuntu: sudo apt update && sudo apt install gnupg
  • Arch Linux: sudo pacman -Syu gnupg

1.2. Choose a Passphrase Prompt and Unlocking Policy

GnuPG uses gpg-agent to unlock private keys and a pinentry program for password dialogs. A GUI prompt works with terminal mail clients too; a tiling window manager does not require a terminal prompt.

  • Desktop: use a graphical prompt, such as pinentry-gnome3 (Debian/Ubuntu: sudo apt install pinentry-gnome3) or pinentry-qt for Plasma. Arch Linux provides the backends in pinentry.
  • Terminal-only sessions: use pinentry-curses. NeoMutt supports curses and GUI pinentries, but not pinentry-tty. See the NeoMutt encryption guide.

Create ~/.gnupg with private permissions if necessary, then edit its agent configuration:

install -d -m 700 ~/.gnupg
nano ~/.gnupg/gpg-agent.conf

Use one installed backend; check its path with command -v pinentry-gnome3:

pinentry-program /usr/bin/pinentry-gnome3
# For terminal-only use, replace the line above with:
# pinentry-program /usr/bin/pinentry-curses

default-cache-ttl 600
max-cache-ttl 7200

Apply changes with gpgconf --reload gpg-agent. This clears the agent’s cached passphrases, so expect an initial unlock afterward.

The example caches an unlock for ten minutes of inactivity, with a two-hour absolute maximum. Each use resets the inactivity timer. These are agent settings; changing NeoMutt’s pgp_timeout does not configure the GPGME agent cache. A longer cache trades fewer prompts for longer access to unlocked keys. GnuPG agent options

For unlocking through your desktop login, use a Pinentry build with Secret Service support and an encrypted desktop keyring. Select the prompt’s option to remember the passphrase. Verify that the keyring unlocks during normal password login; automatic login may leave it locked. A curses Pinentry build linked with libsecret can also retrieve previously saved passphrases without a GUI. Its terminal dialog may not offer a save option, so initial enrollment and automatic keyring unlocking must be configured separately. Test the capabilities of your installed build. External storage is separate from the agent’s cache and can supply the password again after its timeout. Do not set no-allow-external-cache when choosing this workflow. Pinentry’s Secret Service implementation

pam-gnupg is an alternative when the GPG passphrase matches the login password; it does not unlock arbitrary existing passphrases and does not work with automatic login. Include both signing-key and encryption-subkey keygrips when those operations need unlocking. See the upstream setup guide.

Keep a recoverable copy of the passphrase in your password manager. Storing a GPG key’s passphrase in a pass store encrypted solely to that same key creates a circular dependency. SMTP credentials in pass are a separate matter.

Encryption itself uses the recipient’s public key. A private-key password prompt normally comes from signing, decryption, or a password-manager lookup used for SMTP authentication.


2. Creating Your Master Key in the Terminal

We will now create your OpenPGP key using the recommended interactive process.

  1. Start the key generation process:

    gpg --full-generate-key
  2. Follow the prompts. The recommended choices are secure and robust:

    • Key Type: Select RSA and RSA by its label; menu numbers can differ between versions. RSA-4096 is a compatibility-oriented choice, not a requirement to replace an existing supported key.
    • Key Size: Enter 4096 bits.
    • Expiration Date: Enter 2y (for 2 years). Expiration encourages maintenance and lets correspondents stop using outdated keys. It does not prevent a stolen private key from decrypting old mail. Renewal is covered in Part 3.5.
    • Confirm that the expiration date is correct by typing y.
  3. Provide Your User ID:

    • Real name: Enter your full name.
    • Email address: Enter the email address for this key.
    • Comment: You can leave this blank.
    • Confirm your details by typing O (for Okay).
  4. Set Your Passphrase: A secure prompt will now appear (thanks to pinentry!). This will be the master password for your new private key.

⚠️ PASSPHRASE QUALITY IS CRITICAL
A weak passphrase makes your encrypted data vulnerable. Consider using a method like **Diceware** to generate a sequence of random words. If you lose this passphrase, you lose access to all data encrypted with this key permanently.

Congratulations, you have successfully created a secure, command-line-native OpenPGP key!


3. Essential Security Practices (Don’t Skip This!)

Immediately after creation, you must secure your new key for long-term use.

3.1. Identify the Full Fingerprint

Use a full fingerprint to distinguish keys, especially when an address has more than one:

gpg --list-secret-keys --keyid-format LONG --with-subkey-fingerprint

YOUR-FINGERPRINT below means the complete fingerprint of your primary key, copied from this output. An encryption subkey has its own fingerprint. Public-key operations do not require exporting private material.

3.2. Back Up Your Private Key

Create a passphrase-protected export in a private directory:

install -d -m 700 ~/openpgp-backup
umask 077
gpg --armor --export-secret-keys YOUR-FINGERPRINT > ~/openpgp-backup/private-key-backup.asc
gpg --show-keys --with-fingerprint ~/openpgp-backup/private-key-backup.asc

Check the export command’s exit status, ensure the file is nonempty, and compare fingerprints. Parsing a backup is not a complete restore test. In a separate, temporary GnuPG home, import it and test signing and decrypting a disposable message using the saved passphrase. Remove that temporary key store after verification. Keep verified backups and revocation certificates in secure offline storage. GnuPG key management


3.3. Create a Revocation Certificate

This is your emergency button. Use your Key-ID to specify which key to revoke.

umask 077 && gpg --gen-revoke --armor YOUR-FINGERPRINT > revocation-cert.asc

Store this file as securely as your private key backup.

3.4. Verify the Correspondent’s Fingerprint

A public key found on a website or keyserver still needs identity verification. Compare its full fingerprint over an independent, authenticated channel with the intended person:

gpg --fingerprint recipient@example.org

After comparison, record a local certification using the verified full fingerprint:

gpg --local-user YOUR-FINGERPRINT --lsign-key RECIPIENT-FINGERPRINT

A local signature is non-exportable. Key validity (whether a key belongs to an identity) differs from ownertrust (whether someone reliably certifies other people’s keys). Verifying one correspondent does not automatically make their certifications of others trustworthy. Do not mark other people’s keys as ultimately trusted to bypass warnings. GnuPG key certification

Thunderbird maintains its own acceptance decisions; set the recipient’s acceptance status there separately. Thunderbird OpenPGP FAQ


3.5. Extend Primary and Encryption-Subkey Validity

Check both the primary key and encryption subkeys before renewing. For a primary key and all currently valid, non-revoked subkeys:

gpg --quick-set-expire YOUR-FINGERPRINT 2y
gpg --quick-set-expire YOUR-FINGERPRINT 2y '*'
gpg --list-keys --with-subkey-fingerprint YOUR-FINGERPRINT

The quoted '*' does not select already expired subkeys. To renew those, supply their exact subkey fingerprints instead. Re-export and distribute the updated public key, update its copies in other clients, and refresh your private backup. GnuPG expiration commands


4. Making Your Key Discoverable (Optional)

A public key that only exists on your computer is like a phone number you never give out. For others to send you encrypted mail easily, you should distribute your public key.

4.1. Your Website

Export only the public key:

gpg --armor --export YOUR-FINGERPRINT > public.asc

Publish it over HTTPS, for example at https://example.org/public.asc, together with its full fingerprint. Website hosting provides a distribution channel; independent fingerprint verification remains useful.

4.2. A Public Keyserver

Publishing a public key can expose identity information. For keys.openpgp.org, uploading and verifying an address are separate steps:

gpg --keyserver hkps://keys.openpgp.org --send-keys YOUR-FINGERPRINT

--send-keys alone does not request the address-verification email. Use the service’s upload page and request verification there if you want email-address lookup. See its GnuPG instructions. Never upload a private-key export.


5. Going Public: Your Contact Page and Email Signature

Now that you have ways to distribute your key, you need to tell people about them.

5.1. On Your Website’s Contact Page

Add a section like this to your contact page. It provides clear instructions for everyone.

<h3>Digital Contact & Verification</h3>
<p><strong>E-Mail:</strong> your.name@example.com</p>
<p>
    <strong>OpenPGP Key:</strong> For encrypted communication, you can get my public key here:
    <ul>
        <li><a href="/public.asc" download>Download Public Key</a></li>
        <li><strong>Or import via command line:</strong><br>
            <code>curl --fail --show-error --location https://example.org/public.asc | gpg --import</code>
        </li>
    </ul>
    <strong>Fingerprint for Verification:</strong><br>
    <code>YOUR FINGERPRINT IN 4-DIGIT BLOCKS</code>
</p>
<p><em>Policy: All legitimate emails from me will be digitally signed with this key.</em></p>

5.2. In Your Email Signature

A compact, professional signature in every email reinforces trust and makes verification easy.

-- 
Your Name

Website & PGP Key: https://example.org/contact
GPG Fingerprint: YOUR FINGERPRINT IN 4-DIGIT BLOCKS

This signature doesn’t overload the email but provides everything a recipient needs to verify your identity and find your key.


6. Integration with Thunderbird

Thunderbird uses its own OpenPGP key store by default. Creating a key in GnuPG does not automatically make it available there. Choose one of these workflows. Thunderbird OpenPGP FAQ

6.1. Thunderbird’s Built-In Key Store

  1. Open Account Settings → End-To-End Encryption for user@example.org.
  2. Open OpenPGP Key Manager → File → Import Secret Key(s) From File.
  3. Select private-key-backup.asc from Part 3.2, enter its passphrase, and check the fingerprint.
  4. Assign the imported personal key to the correct account and identity.
  5. Set a Primary Password in Thunderbird’s privacy/security settings.

Thunderbird replaces an imported key’s protection with an automatically generated password. Without a Primary Password, a copied profile does not provide effective protection for those keys. Restrict profile-directory permissions too. This workflow has a separate unlock from GnuPG.

6.2. Share GnuPG’s Private-Key Operations

For a shared agent or hardware-token workflow, install GnuPG and GPGME. Enable mail.openpgp.allow_external_gnupg in Thunderbird’s Config Editor. Under the account’s End-To-End Encryption settings, choose Add Key → Use your external key through GnuPG and enter the primary key’s 16-character long ID. Import the matching public key into Thunderbird and accept it. Repeat per identity.

This delegates signing and decryption to GnuPG; public-key operations and acceptance remain in Thunderbird. Existing internal private-key copies can still service decryption. Remove duplicate private material only after checking recoverable backups and successful external signing/decryption. See Mozilla’s external-GnuPG setup.

In either workflow, choose encryption/signing explicitly in the compose window and verify recipient-key acceptance. Test receiving, signing, decryption, and reading your own sent copy.


7. Integration with NeoMutt

Edit the configuration actually loaded by your installation: commonly ~/.config/neomutt/neomuttrc or ~/.config/mutt/muttrc. Use GPGME with your full primary fingerprint:

set crypt_use_gpgme = yes
set pgp_use_gpg_agent = yes
set crypt_verify_sig = yes
set pgp_show_unusable = no

set pgp_default_key = "YOUR-FINGERPRINT"
unset pgp_sign_as
set pgp_self_encrypt = yes
set fcc_clear = no

set crypt_auto_sign = yes
set crypt_auto_encrypt = no
set crypt_reply_encrypt = yes
set crypt_reply_sign = yes
set crypt_reply_sign_encrypted = yes

pgp_default_key selects your personal key for self-encryption and, without a separate pgp_sign_as, signing. Self-encryption lets you reopen encrypted sent mail. Use a separate signing selector only when needed; a trailing ! forces an exact key/subkey and should not be copied blindly into an encryption-key selector. NeoMutt crypto options, encrypt-to-self guide

These settings automatically sign and protect replies to encrypted mail. They do not encrypt every new message. Confirm the compose screen’s security state before sending. Passphrase caching belongs to gpg-agent as described in Part 1.2.

8. Handle Multiple Accounts Without Inheriting Another Identity

Separate keys can help separate personal and work identities. Regardless of your key layout, explicitly assign the correct key to each sending identity.

8.1. Thunderbird

Repeat Part 6 for each account and identity. Check the selected key rather than assuming the mapping is automatic.

8.2. NeoMutt

For each account file, explicitly set all account-dependent crypto settings. Commenting out an assignment does not reset an earlier account’s value:

# ~/.config/mutt/accounts/personal.muttrc
set from = "personal@example.org"
set pgp_default_key = "PERSONAL-FINGERPRINT"
unset pgp_sign_as
set crypt_auto_sign = yes
set crypt_auto_encrypt = no
# Add the account's normal mailbox and transport settings separately.

Use WORK-FINGERPRINT and work@example.org in the work file. Set crypt_auto_sign = no explicitly if an account should not sign automatically. For an account with no personal OpenPGP key, clear both pgp_default_key and pgp_sign_as, and disable automatic signing; manual signing still requires a valid matching key.

Load account files through your existing switching macros, or a folder hook matching the actual mailbox path:

folder-hook '^imaps://personal@example\.org/' 'source ~/.config/mutt/accounts/personal.muttrc'
source ~/.config/mutt/accounts/personal.muttrc

For local Maildir installations, match the local folder path instead. Folder hooks select configuration by the current mailbox; they do not automatically follow a manually edited From header. Recheck the sending identity and key when changing From. NeoMutt encryption guide

Test switching in both directions, including an account without a key. A disposable signed/encrypted message should identify the intended signer and remain readable in your sent folder.


9. Transfer Keys Between Computers

Use explicit exports/imports rather than overwriting a live ~/.gnupg directory with an archive containing sockets, locks, and host-specific configuration.

On the source machine, prepare a private directory and export:

install -d -m 700 ~/openpgp-transfer
umask 077
gpg --armor --export YOUR-FINGERPRINT > ~/openpgp-transfer/public.asc
gpg --armor --export-secret-keys YOUR-FINGERPRINT > ~/openpgp-transfer/private.asc

Transfer through a protected channel. On the destination:

install -d -m 700 ~/.gnupg
gpg --import /secure/transfer/public.asc
gpg --import /secure/transfer/private.asc
gpg --list-secret-keys --with-subkey-fingerprint

Verify fingerprints, establish trust locally, and test signing and decryption before removing temporary exports. Preserve your verified offline backups. Configure Pinentry for that machine; copy NeoMutt settings without passwords. For Thunderbird, repeat Part 6: its default key store is separate. GnuPG key management

Never use chmod 600 ~/.gnupg/*: directories need their execute bit. If existing permissions need repair, inspect ownership and links first, then set directories and regular files separately without following symlinks:

find ~/.gnupg -type d -exec chmod 700 {} +
find ~/.gnupg -type f -exec chmod 600 {} +

Desktop-keyring entries and Thunderbird Primary Passwords have their own lifecycle. Copying GnuPG keys alone does not reproduce their unlocking configuration.


10. Quick Troubleshooting

  <colgroup>
    
      <col width="40%">
    
      <col width="60%">
    
  </colgroup>


<thead><tr><th>Problem</th><th>Check</th></tr></thead><tbody>
Repeated password promptsCheck agent cache timeouts, desktop-keyring integration, and which private key is being used. SMTP credentials retrieved through pass can cause a separate unlock.
No password promptThe key may already be cached. If the operation fails, check Pinentry and the session’s display/terminal environment. Reloading the agent clears its cache.
Key not found or expiredCheck the full fingerprint, secret-key availability, and primary/subkey expiry dates.
Wrong signer after switching accountsExplicitly set/reset the per-account key and signing policy; verify the From address.
Cannot read an encrypted sent copyCheck pgp_self_encrypt, pgp_default_key, and availability of your encryption subkey.
Unknown or unaccepted correspondentIndependently verify the fingerprint. Record GnuPG certification and Thunderbird acceptance separately.

Sources

11. Conclusion

By starting with a solid foundation—creating your keys directly in the terminal—you have built a robust and universal encryption setup. This method not only avoids platform-specific pitfalls but also equips you with a deeper understanding of how PGP works. By performing essential maintenance like backups, establishing a clear public identity, and renewing your keys, you ensure your digital identity remains secure and trustworthy for the long term.

📚OPENPGP DOCUMENTATION 🛡️GNUPG DOCUMENTATION