Skip to content

GPG Cheatsheet

This is a quick reference for the most common GPG commands. It assumes you already have a key pair.

Use this for files, signing, and Git commits.


Key Management

TaskCommand (Linux)Notes
List your keysgpg --list-keysShows public keys
List secret keysgpg --list-secret-keysShows private keys
Generate a new key pairgpg --full-generate-keyFollow prompts, choose type and passphrase
Export public keygpg --export -a "Name" > public.keySend this to others
Export private keygpg --export-secret-keys -a "Name" > private.keyBackup only, never share
Import a keygpg --import filename.keyFor receiving someone’s public key
Create revocation certificategpg --output revoke.asc --gen-revoke "Name"Keep offline

Encrypt / Decrypt Files

TaskCommandNotes
Encrypt a filegpg -e -r "Recipient Name" file.txtProduces file.txt.gpg
Decrypt a filegpg -d file.txt.gpg > file.txtRequires private key
Encrypt for multiple recipientsgpg -e -r "Alice" -r "Bob" file.txtOnly listed recipients can decrypt

Sign / Verify Files

TaskCommandNotes
Sign a file (detached)gpg --detach-sign file.txtCreates file.txt.sig
Verify signaturegpg --verify file.txt.sig file.txtChecks file integrity and signer
Sign a file (inline)gpg --clearsign file.txtSignature embedded in the file

Git Commit Signing

TaskCommandNotes
Set default GPG key in Gitgit config --global user.signingkey <KEY_ID>Use your private key ID
Sign a commitgit commit -S -m "Commit message"-S signs the commit
Verify commitsgit log --show-signatureShows which commits are signed

Tips

  • Always backup your private key and revocation certificate
  • Never share your private key
  • Use strong passphrases and rotate keys if compromised
  • Check your key fingerprints before sharing