GnuPG Cheatsheet - Encryption
The workflow most people actually repeat is: create a keypair once, export your public key to a paste or keyserver, then encrypt to others or sign your own archives. The two details that trip people up are keeping the private key safe and revocable, and knowing who you are encrypting to (their public key, not yours). This table links key lifecycle, encrypt/sign, and verify so PGP work flows end-to-end.
Key Generation 8
gpg --full-generate-keyInteractive key pair generation
gpg --quick-generate-key "Name <email>"Quick key generation
gpg --list-keysList all public keys
gpg --list-secret-keysList all secret keys
gpg --list-keys KEYIDShow a key's details
gpg --edit-key KEYIDEdit a key interactively
gpg --delete-key KEYIDDelete a public key
gpg --delete-secret-key KEYIDDelete a secret key
Import & Export 6
gpg --export -a KEYID > pubkey.ascExport a public key to ASCII
gpg --export-secret-keys -a KEYID > private.ascExport a secret key (keep it safe)
gpg --import pubkey.ascImport a public key
gpg --import private.ascImport a secret key
gpg --send-keys KEYID --keyserver keyserver.ubuntu.comUpload a public key to a keyserver
gpg --recv-keys KEYIDFetch a public key from a keyserver
Encrypt & Decrypt 6
gpg -e -r recipient@domain.com secret.txtEncrypt a file with a recipient's public key
gpg -e -r user@domain.com -o secret.txt.gpg secret.txtEncrypt and set the output filename
gpg -d secret.txt.gpg > secret.txtDecrypt to a file
gpg -c secret.txtSymmetric encryption (password only)
gpg -d secret.txt.gpgDecrypt a symmetric file
echo "message" | gpg -e -r user@domain.comEncrypt piped text
Sign & Verify 6
gpg -s document.txtCreate a signature (.gpg binary)
gpg --clear-sign document.txtCreate a clear-text signature
gpg -b document.txtCreate a detached signature (.sig)
gpg --verify document.txt.sig document.txtVerify a detached signature
gpg --verify document.txt.ascVerify a clear-text signature file
gpg --detach-sign -a file.tar.gzCreate an ASCII detached signature
Trust & Keyserver 5
gpg --edit-key KEYID\n> trustSet a key's trust level (interactive)
gpg --sign-key KEYIDSign someone's public key (endorsement)
gpg --refresh-keysRefresh all keys from the keyserver
gpg --search-keys "user@domain.com"Search the keyserver for a key
gpg --fingerprint KEYIDShow a key fingerprint to verify identity
Git Signing 6
git config --global user.signingkey KEYIDSet the signing key for Git
git config --global commit.gpgsign trueAuto-sign all commits
git commit -S -m "message"Create a GPG-signed commit
git tag -s v1.0 -m "release"Create a GPG-signed tag
git verify-commit HEADVerify the latest commit's signature
gpgconf --kill gpg-agentRestart gpg-agent (fix passphrase cache)
Tips
- Sign Git commits: git config --global commit.gpgsign true with a GPG key.
- gpg --armor (-a) produces ASCII keys/signatures for easy text transfer.
- Back up keys: gpg --export-secret-keys -a KEYID > private.asc, store safely.
- gpg-agent caches the passphrase so you don't retype it.
- gpgconf --kill gpg-agent restarts the agent to fix cache issues.
- A key fingerprint verifies authenticity - always check it after importing.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us