// Your keys. Your data. Your rules.
ENCRYPTION IS RESISTANCE.
In a world where corporations and governments vie for access to your data, encryption is your shield. GPG (GNU Privacy Guard) is the gold standard for asymmetric encryption—a technology that gives you the power to communicate privately, sign documents cryptographically, and verify the authenticity of messages.
NO MORE EXCUSES.
"I have nothing to hide" is the argument of someone who doesn't understand privacy. Privacy isn't about hiding—it's about consent. You decide who sees your data. GPG makes that decision enforceable, even against sophisticated adversaries.
LEARN THE TOOLS THAT MATTER.
This guide covers everything from generating your first key pair to managing a web of trust. By the end, you'll encrypt emails, sign code commits, and verify signatures like a privacy professional.
12 lessons. Complete GPG control.
What is GPG? Installing GnuPG and understanding cryptographic fundamentals.
BeginnerCreating your first key pair. Algorithm choices and security considerations.
BeginnerListing, viewing, and managing your keys. Keyrings and key storage.
BeginnerEncrypting files and messages. Symmetric vs asymmetric encryption.
BeginnerDecrypting messages and files. Handling encrypted communications.
BeginnerSigning messages and files. Understanding signature types.
IntermediateVerifying signatures. Trust models and signature verification.
IntermediateSigning other keys. Keysigning parties and trust propagation.
IntermediateUsing subkeys for daily work. Creating and using revocation certificates.
AdvancedHardware tokens. YubiKey and OpenPGP cards for key protection.
AdvancedSigning Git commits and tags. Verified commits in GitHub/GitLab.
AdvancedSetting up email with GPG. Thunderbird and webmail integration.
AdvancedGPG (GNU Privacy Guard, also called GnuPG or GPG) is a complete and free implementation of the OpenPGP standard. It allows you to encrypt and sign your data and communications, featuring a versatile key management system along with access modules for all kinds of public key directories.
GPG is the backbone of private digital communication. It's used by journalists, activists, developers, and anyone who values their digital privacy. It's been battle-tested for over 20 years.
Understanding the difference is crucial:
Same key encrypts and decrypts. Like a physical lock with one key.
# Encrypt with password gpg --symmetric --armor message.txt # Decrypt with password gpg --decrypt message.txt.asc
Two keys: public key encrypts, private key decrypts. Like a mailbox—anyone can drop mail in (encrypt with public key), but only the owner can retrieve it (decrypt with private key).
# Encrypt for recipient (using their public key) gpg --encrypt --armor --recipient alice@example.com message.txt # Decrypt (using your private key) gpg --decrypt message.txt.asc
# Debian/Ubuntu sudo apt install gnupg # Fedora sudo dnf install gnupg # Arch sudo pacman -S gnupg
# Via Homebrew brew install gnupg
# Download from https://www.gpg4win.org/
Verify your installation:
gpg --version
gpg --full-generate-key
You'll be prompted through an interactive wizard:
Key expiration is a safety feature:
You can always extend expiration later without regenerating keys.
Do this IMMEDIATELY after creating your key:
# Replace with your key ID or email gpg --output revocation_cert.asc --gen-revoke your@email.com # Store this securely (USB drive in safe, print paper copy) # You need this if you: # - Lose your private key # - Forget your passphrase # - Want to retire the key
# List your secret keys (private keys you own) gpg --list-secret-keys # List your public keys gpg --list-keys # List all keys with fingerprints gpg --fingerprint
Output shows KeyID, creation date, and User ID (name + email).
# Export your public key to share gpg --armor --export your@email.com > my_public_key.asc # Export secret key (backup) gpg --armor --export-secret-keys your@email.com > my_secret_key.asc # Export with specific key ID gpg --armor --export 0x1234567890ABCDEF > public_key.asc
# Import a public key gpg --import friend_public_key.asc # Import a secret key (for migration/backup) gpg --import my_secret_key.asc # Import from keyserver gpg --keyserver keyserver.ubuntu.com --search-keys friend@email.com gpg --keyserver keyserver.ubuntu.com --recv-keys 0x1234567890ABCDEF
Public keys are distributed via key servers:
# Upload your public key gpg --keyserver keyserver.ubuntu.com --send-keys 0xYOURKEYID # Search for a key gpg --keyserver keyserver.ubuntu.com --search-keys "John Doe" # Refresh (download latest versions) gpg --refresh-keys
Encrypt with a password (no key pair needed):
# Encrypt file gpg --symmetric --armor secret.txt # Output: secret.txt.asc # Or with specific algorithm gpg --symmetric --cipher-algo AES256 --armor secret.txt
The output is ASCII-armored (readable text), suitable for email.
Encrypt for a specific recipient (using their public key):
# Encrypt for recipient
gpg --encrypt --armor --recipient friend@example.com secret.txt
# Encrypt for multiple recipients
gpg --encrypt --armor \
--recipient alice@example.com \
--recipient bob@example.com \
secret.txt
# Encrypt and sign (proves you sent it)
gpg --encrypt --sign --armor --recipient friend@example.com secret.txt
# Compression (default - recommended) gpg --compress-keys ... # Don't compress keys separately gpg --compress-sigs ... # Don't compress signatures separately # Algorithm selection gpg --cipher-algo AES256 ... # Strongest gpg --cipher-algo CAMELLIA256 ... # Batch encryption gPG --encrypt-files --recipient friend@email.com *.txt
# Tar first, then encrypt tar czf - mydirectory/ | gpg --symmetric --armor -o mydirectory.tar.gz.asc # Or use tar with gpg tar -czf - mydirectory | gpg --encrypt --recipient friend@email.com -o mydirectory.tar.gz.gpg
# Decrypt a file (will prompt for passphrase if needed) gpg --decrypt secret.txt.asc # Decrypt to specific file gpg --decrypt secret.txt.asc --output decrypted.txt # Decrypt symmetric-encrypted file gpg --decrypt secret.txt.asc
# Decrypt and view directly gpg --decrypt message.txt.asc 2>/dev/null | less # Decrypt tar archive gpg --decrypt backup.tar.gz.asc | tar tzf - # Decrypt and extract gpg --decrypt backup.tar.gz.asc | tar xzf -
gpg-agent caches your passphrase:
# Default cache: 10 minutes # Configure in ~/.gnupg/gpg-agent.conf # Clear cache echo RELOADAGENT | gpg-connect-agent # View cache settings gpg-agent --daemon gpg-agent --use-standard-socket
Digital signatures prove:
# Create separate signature file gpg --sign document.txt # Output: document.txt.gpg (binary) # ASCII-armored signature gpg --armor --sign document.txt # Output: document.txt.asc # Clearsign (message + signature in one readable file) gpg --clearsign message.txt # Output: message.txt.asc # Detached signature (separate file) gpg --armor --detach-sign document.txt # Output: document.txt.sig
# Sign with specific key gpg --local-user 0xKEYID --sign document.txt # Set default key in ~/.gnupg/gpg.conf default-key 0xYOURKEYID # Or use GPG_KEY environment variable GPG_KEY=0xYOURKEYID gpg --sign document.txt
# Verify signed file (includes original) gpg --verify document.txt.gpg # Verify clearsigned file gpg --verify message.txt.asc # Verify detached signature gpg --verify document.txt.sig document.txt
Good signature output:
gpg: Signature made Mon Jan 15 10:30:00 2024 gpg: using RSA key 0x1234567890ABCDEF gpg: Good signature from "John Doe"
After verification, GPG tells you:
# Download software + signature wget https://example.com/software.tar.gz wget https://example.com/software.tar.gz.sig # Import developer's key (do this once) gpg --keyserver keyserver.ubuntu.com --recv-keys 0xDEADBEEF # Verify gpg --verify software.tar.gz.sig software.tar.gz
GPG uses a "web of trust" instead of central authorities:
# Sign someone's public key (after verifying their identity!) gpg --sign-key friend@example.com # Limited signature (won't be uploaded by default) gpg --sign-key --local-user 0xYOURKEYID friend@example.com # Export the signature to give to them gpg --export-options export-minimal --export friend@example.com > friend_key.asc
In-person events where people verify each other's identities and sign keys:
Subkeys separate your signing/encryption capabilities from your master key:
# Edit your key gpg --edit-key your@email.com # At gpg> prompt: gpg> addkey # Choose: RSA (sign only) or RSA (encrypt only) # Choose size: 4096 # Set expiration # Save: save # List subkeys gpg> list
You MUST create this when you create your key:
# Create revocation certificate gpg --output revocation.asc --gen-revoke your@email.com # To use it later: gpg --import revocation.asc gpg --send-keys YOURKEYID
Reasons for revocation:
Smart cards/hardware tokens keep your private keys physically secure:
Keys never leave the device. Even if your computer is compromised, attacker can't get your keys.
# Install required software sudo apt install libusb-1.0-0 libpcsclite1 libccid pcscd # Check if YubiKey is detected gpg --card-status
gpg --edit-card # At gpg> prompt: gpg> admin # Generate new key on card gpg> generate # Or move existing key to card gpg> key 1 gpg> keytocard
Signed commits prove:
# Tell Git your key git config --global user.signingkey 0xYOURKEYID # Default to signing commits git config --global commit.gpgsign true # Default to signing tags git config --global tag.gpgsign true # Use GPG program git config --global gpg.program gpg
# Sign a commit git commit -S -m "My signed commit" # Sign a tag git tag -s v1.0 -m "My signed tag" # Push signed commits git push # On GitHub: Look for "Verified" badge
# In Enigmail: # - OpenPGP > Key Management # - You can generate new keys or import existing # - Enable encryption by default in Preferences
# Option 1: Keyserver gpg --keyserver keyserver.ubuntu.com --send-keys YOURKEY # Option 2: Attach to email signature # Add to email signature: # -----BEGIN PGP PUBLIC KEY BLOCK----- # [your public key] # -----END PGP PUBLIC KEY BLOCK----- # Option 3: Personal website # Host your key at https://yourdomain.com/key.asc
You've completed the GPG mastery guide. You now know how to:
Remember: