DevTools Logo

GPG / PGP Encryption Cheat Sheet

GPG key generation, symmetric and asymmetric encryption, signing, key management, and revocation.

Security Tools
gpg
pgp
encryption

GPG (GnuPG) implements the OpenPGP standard for encryption and signing. It supports symmetric ciphers for files and asymmetric public/private key pairs for identity, confidentiality, and non-repudiation.

Generate and manage keys

bash
gpg --full-generate-key
gpg --list-keys
gpg --list-secret-keys
gpg --export --armor you@example.com > public.asc
gpg --export-secret-keys --armor you@example.com > private.asc
gpg --import public.asc
Table
CommandPurpose
--full-generate-keyInteractive key creation.
--list-keysList public keys.
--list-secret-keysList private keys.
--export --armorExport a public key as ASCII armor.
--importImport a key.

Symmetric encryption

Symmetric encryption uses a single passphrase (no key pair).

bash
gpg --symmetric --cipher-algo AES256 secret.txt
gpg --decrypt secret.txt.gpg

Asymmetric encryption

Encrypt to a recipient's public key; only their private key can decrypt.

bash
gpg --encrypt --recipient you@example.com secret.txt
gpg --decrypt secret.txt.gpg

Signing and verification

bash
gpg --sign document.txt                 # embedded signature
gpg --clearsign document.txt            # readable text + signature
gpg --detach-sign document.txt          # separate .sig file
gpg --verify document.txt.sig document.txt
Table
CommandPurpose
--detach-signProduce a separate signature file.
--verifyCheck a signature.
--clearsignSignature readable in plain text.

Revocation

bash
gpg --gen-revoke you@example.com > revoke.asc
gpg --import revoke.asc

References