The Ultimate Guide to Email Encryption with OpenPGP

| Keys, envelopes, and a carefully lit evening desk. |
Table of Contents đ
- Changelog
- 1. Pre-Flight Check â Your Systemâs Foundation
- 2. Creating Your Master Key in the Terminal
- 3. Essential Security Practices (Donât Skip This!)
- 4. Making Your Key Discoverable (Optional)
- 5. Going Public: Your Contact Page and Email Signature
- 6. Integration with Thunderbird
- 7. Integration with NeoMutt
- 8. Handle Multiple Accounts Without Inheriting Another Identity
- 9. Transfer Keys Between Computers
- 10. Quick Troubleshooting
- Sources
- 11. Conclusion
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
| Date | Change |
|---|---|
| 2026-10-16 | Fix passphrase caching, terminal prompts, Thunderbird storage, and key transfer. |
| 2025-07-15 | Major 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-15 | Initial 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) orpinentry-qtfor Plasma. Arch Linux provides the backends inpinentry. - Terminal-only sessions: use
pinentry-curses. NeoMutt supports curses and GUI pinentries, but notpinentry-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.confUse 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 7200Apply 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.
Start the key generation process:
gpg --full-generate-keyFollow 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
4096bits. - 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.
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).
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 |
|
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-fingerprintYOUR-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.ascCheck 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.ascStore 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.orgAfter comparison, record a local certification using the verified full fingerprint:
gpg --local-user YOUR-FINGERPRINT --lsign-key RECIPIENT-FINGERPRINTA 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-FINGERPRINTThe 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.ascPublish 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 BLOCKSThis 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
- Open Account Settings â End-To-End Encryption for
user@example.org. - Open OpenPGP Key Manager â File â Import Secret Key(s) From File.
- Select
private-key-backup.ascfrom Part 3.2, enter its passphrase, and check the fingerprint. - Assign the imported personal key to the correct account and identity.
- 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 = yespgp_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.muttrcFor 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.ascTransfer 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-fingerprintVerify 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
| Repeated password prompts | Check 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 prompt | The 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 expired | Check the full fingerprint, secret-key availability, and primary/subkey expiry dates. |
| Wrong signer after switching accounts | Explicitly set/reset the per-account key and signing policy; verify the From address. |
| Cannot read an encrypted sent copy | Check pgp_self_encrypt, pgp_default_key, and availability of your encryption subkey. |
| Unknown or unaccepted correspondent | Independently verify the fingerprint. Record GnuPG certification and Thunderbird acceptance separately. |
Sources
- GnuPG agent options
- GnuPG key management
- Pinentry Secret Service implementation
- Thunderbird OpenPGP FAQ
- Mozilla external-GnuPG configuration
- NeoMutt crypto configuration reference
- NeoMutt encrypt-to-self guide
- keys.openpgp.org GnuPG usage
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.
đ đĄď¸





