What it does
gpg manages a keyring of OpenPGP keys. In operations you use it mostly to verify downloads and package signatures (RPM repos, HashiCorp releases), to sign releases and Git tags, and sometimes to encrypt files for a person. RPM and DNF check package signatures with GPG keys imported by rpm --import.
How to write it
gpg [OPTIONS] COMMAND [ARGS]Main parts
Commands
--full-generate-key/--quick-generate-key- Make a key pair.
--list-keys/--list-secret-keys- Show keys.
--importFILE/--export-aID- Import / export public keys.
--verifySIG[FILE]- Check a signature.
--detach-sign-aFILE- Make a separate signature file.
--clearsignFILE- Sign a text file in place.
-e-rIDFILE- Encrypt for a person.
-dFILE- Decrypt.
-cFILE- Encrypt with a passphrase (symmetric).
--fingerprintID- Show the fingerprint (compare it!).
--edit-keyID- Trust, expire, add sub-keys.
--gen-revokeID- Make a revocation certificate.
Options 6
Most used
Flags
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Make a key
gpg --quick-generate-key "s0sta release signing" ed25519 sign 2y gpg --list-secret-keys --keyid-format long2Verify a download (HashiCorp example)
3Check the fingerprint of an imported key
gpg --import hashicorp.asc gpg --fingerprint security@hashicorp.com4Sign a release file
gpg --detach-sign -a shop-1.4.0.tar.gz gpg --verify shop-1.4.0.tar.gz.asc shop-1.4.0.tar.gz5Encrypt a file for a colleague
gpg --import colleague.asc gpg -e -a -r colleague@example.com handover.txt gpg -d handover.txt.asc6Encrypt with only a passphrase
gpg -c --cipher-algo AES256 notes.txt7Check RPM package signatures
8Sign Git tags with GPG
9Export your public key for GitHub
gpg --export -a 0x1234ABCD5678EF9010Make a revocation certificate (keep it offline)
gpg --gen-revoke 0x1234ABCD5678EF90 > revoke.asc
Nothing matches this filter.
Watch out
- Always compare fingerprints from a second trusted source; a key with the right name can be fake.
- Back up the secret key and the revocation certificate offline.
Files
~/.gnupg/- Keyring and settings.
Tips to remember
- For new projects, SSH signing (Git) and age (files) are simpler; GPG is still needed for RPM and many downloads.
Exit codes
0 | Success (good signature). |
1 | Bad signature. |
2 | Other error. |