GPG Cheat Sheet
GnuPG commands for encrypting files, signing, and managing keys — symmetric and public-key workflows.
Overview
GnuPG (gpg) is the standard tool for OpenPGP encryption and signing. Use symmetric mode (a passphrase) for quick file encryption, or public-key mode (recipient's key) for sending data only they can read. It also verifies signatures on downloaded software and decrypts files recovered during forensics/CTFs.
Authorized use only. Handle keys and recovered secrets only with permission.
Symmetric (passphrase) encryption
Encrypt with a passphrase → secret.txt.gpg
gpg -c secret.txtDecrypt to stdout
gpg -d secret.txt.gpgDecrypt to a file
gpg -o secret.txt -d secret.txt.gpgForce AES-256
gpg --cipher-algo AES256 -c secret.txtKey management
Generate a new key pair (interactive)
gpg --full-generate-keyList public keys in your keyring
gpg --list-keysList private keys with long key IDs
gpg --list-secret-keys --keyid-format LONGExport your public key (ASCII armor)
gpg --export -a "you@example.com" > public.ascImport someone's public key
gpg --import public.ascRemove a private key
gpg --delete-secret-keys <keyid>Public-key encryption
Encrypt for a recipient → msg.txt.gpg
gpg -e -r "alice@example.com" msg.txtEncrypt + ASCII armor (.asc, email-safe)
gpg -e -a -r "alice@example.com" msg.txtDecrypt with your private key
gpg -d msg.txt.gpgSigning & verification
Create a detached signature (file.iso.asc)
gpg --detach-sign -a file.isoVerify a detached signature
gpg --verify file.iso.asc file.isoSign keeping the text readable
gpg --clearsign message.txtQuick one-liners
Decrypt a file recovered in a CTF/forensics case
gpg --batch --passphrase 'P@ss' -d loot.gpgEncrypt a whole folder (tar then gpg)
tar czf - mydir | gpg -c -o mydir.tar.gz.gpgFetch a public key from a keyserver
gpg --keyserver hkps://keys.openpgp.org --recv-keys <keyid>Show a key's fingerprint
gpg --fingerprint you@example.comTips
- Use -a (ASCII armor) whenever the output must travel through email or text.
- --batch --passphrase lets you script decryption (handy for brute-forcing CTF passphrases with a wordlist).
- Always verify software signatures against a fingerprint you trust, not just 'Good signature'.
- Back up your secret key and revocation certificate somewhere offline — losing them is unrecoverable.