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.

SysOps·37 commands·Last updated 2026-07-21
gpgEncryptionSigningSecurity

Key Generation 8

gpg --full-generate-key
Interactive key pair generation
gpg --quick-generate-key "Name <email>"
Quick key generation
gpg --list-keys
List all public keys
gpg --list-secret-keys
List all secret keys
gpg --list-keys KEYID
Show a key's details
gpg --edit-key KEYID
Edit a key interactively
gpg --delete-key KEYID
Delete a public key
gpg --delete-secret-key KEYID
Delete a secret key

Import & Export 6

gpg --export -a KEYID > pubkey.asc
Export a public key to ASCII
gpg --export-secret-keys -a KEYID > private.asc
Export a secret key (keep it safe)
gpg --import pubkey.asc
Import a public key
gpg --import private.asc
Import a secret key
gpg --send-keys KEYID --keyserver keyserver.ubuntu.com
Upload a public key to a keyserver
gpg --recv-keys KEYID
Fetch a public key from a keyserver

Encrypt & Decrypt 6

gpg -e -r recipient@domain.com secret.txt
Encrypt a file with a recipient's public key
gpg -e -r user@domain.com -o secret.txt.gpg secret.txt
Encrypt and set the output filename
gpg -d secret.txt.gpg > secret.txt
Decrypt to a file
gpg -c secret.txt
Symmetric encryption (password only)
gpg -d secret.txt.gpg
Decrypt a symmetric file
echo "message" | gpg -e -r user@domain.com
Encrypt piped text

Sign & Verify 6

gpg -s document.txt
Create a signature (.gpg binary)
gpg --clear-sign document.txt
Create a clear-text signature
gpg -b document.txt
Create a detached signature (.sig)
gpg --verify document.txt.sig document.txt
Verify a detached signature
gpg --verify document.txt.asc
Verify a clear-text signature file
gpg --detach-sign -a file.tar.gz
Create an ASCII detached signature

Trust & Keyserver 5

gpg --edit-key KEYID\n> trust
Set a key's trust level (interactive)
gpg --sign-key KEYID
Sign someone's public key (endorsement)
gpg --refresh-keys
Refresh all keys from the keyserver
gpg --search-keys "user@domain.com"
Search the keyserver for a key
gpg --fingerprint KEYID
Show a key fingerprint to verify identity

Git Signing 6

git config --global user.signingkey KEYID
Set the signing key for Git
git config --global commit.gpgsign true
Auto-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 HEAD
Verify the latest commit's signature
gpgconf --kill gpg-agent
Restart 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