Sub topic 8
Verifying GPG Signatures and Understanding Trust
This chapter assumes you can already sign commits and tags with a GPG key, as covered in earlier chapters. It also assumes you know what public and private keys are. Here you will check signatures from other people, read what GnuPG reports, and see why "good signature" and "trusted signer" are different facts.
Two questions verification answers
Verification answers two separate questions:
- Is the signature mathematically valid? The signed data (the commit or tag object) must be unchanged, and the signature must match a public key you hold.
- Do you believe that key belongs to the person it claims? This is trust. Cryptography cannot answer it. You answer it by comparing fingerprints or relying on people you already trust.
A valid signature from an unknown key proves only that someone holding that key made the commit. Anyone can generate a key with the name "Alice" and email [email protected].
Verifying with Git commands
Git calls gpg to do the checking. You have three common entry points.
git log --show-signature -1
git verify-commit HEAD
git tag -v v1.0.0git log --show-signatureprints the GnuPG report above each commit it lists.git verify-commit <commit>checks only the signature and prints the report. Add-vto also print the raw signed commit object.git tag -v <tag>(orgit verify-tag) does the same for tags. It also prints the tag message.
A typical result for a signer you fully trust looks like this:
gpg: Signature made Fri Dec 4 15:00:00 2026 UTC
gpg: using EDDSA key 3AA5C34371567BD2
gpg: Good signature from "Alice Example <[email protected]>" [ultimate]The text in square brackets is the validity GnuPG assigns to the key.
Reading the result
| GnuPG message | Meaning | What to do |
|---|---|---|
| `Good signature ... [ultimate]` or `[full]` | The data matches and the key is trusted. | Nothing. |
| `Good signature ... [unknown]` plus `WARNING: This key is not certified with a trusted signature!` | The data matches, but you have not established whose key it is. | Compare the fingerprint, then certify the key. |
| `BAD signature` | The data differs from what was signed, or the signature is corrupt. | Treat the commit as tampered with. |
| `Can't check signature: No public key` | You do not have the signer's public key. | Import the key, then verify again. |
| `Good signature ... [expired]` | The key has an expiry date that has passed. | See the note on dates below. |
| `Good signature from a revoked key` | The owner has revoked the key. | Do not rely on it. Ask the owner. |
Getting the signer's public key
Verification needs the public key in your keyring. The key can arrive in three ways:
# From a file the owner gave you
gpg --import alice-public.asc
# From a keyserver, by full fingerprint
gpg --keyserver keys.openpgp.org --recv-keys 0123456789ABCDEF0123456789ABCDEF01234567
# Export your own key so others can import it
gpg --armor --export [email protected] > alice-public.ascUse the full 40-character fingerprint when fetching from a keyserver. Short key IDs can be forged, because anyone can generate a key that ends in the same 8 or 16 characters. A keyserver also does not prove ownership. Anybody can upload a key with any name on it.
After importing, print the fingerprint and compare it through a channel you trust, such as in person, a call, or the project's published security page:
gpg --fingerprint [email protected]How GnuPG decides to trust a key
GnuPG's default trust model is the web of trust. It tracks two different values:
- Owner trust is how much you trust a key's owner to certify other keys correctly. You set it yourself.
- Validity is how confident GnuPG is that a key really belongs to the name on it. GnuPG calculates it from certifications (signatures on the key) and your owner-trust settings.
Owner trust levels are unknown, none (never), marginal, full, and ultimate. GnuPG gives your own keys ultimate owner trust automatically. A key becomes valid when a key you ultimately trust has certified it. It can also become valid when enough trusted keys have certified it, by default one fully trusted key or three marginally trusted ones.
Certifying a key you verified
Once you have confirmed a fingerprint, record that decision. The simplest local option is a local signature, which is never exported to keyservers:
gpg --lsign-key 0123456789ABCDEF0123456789ABCDEF01234567Afterward, git log --show-signature reports [full] for that signer and the warning disappears. Use --sign-key instead of --lsign-key only if you intend to publish your certification.
Setting owner trust is a different action. It tells GnuPG to accept that person's own certifications of other keys:
gpg --edit-key [email protected]
# At the gpg> prompt, type: trust
# Choose a level, then type: quitDo not mark a key as ultimately trusted just to silence the warning. Ultimate trust means "treat this like my own key", and everything that key certifies becomes valid for you.
Checking trust in scripts and tables
Reading free-form text is fragile. Git can print the result in a compact form through format placeholders:
git log --pretty=format:"%h %G? %GT %GS <%GK> %s" -5%G?is a one-letter status.%GTis the trust level of the key.%GSis the signer's name.%GKis the key ID.
The status letters are:
| Letter | Meaning |
|---|---|
| `G` | Good signature |
| `B` | Bad signature |
| `U` | Good signature, unknown validity |
| `X` | Good signature that has expired |
| `Y` | Good signature made by an expired key |
| `R` | Good signature made by a revoked key |
| `E` | The signature cannot be checked, for example a missing key |
| `N` | No signature |
A review script should accept only G, and it should be explicit about what it does with U.
Enforcing verification when merging
Git can refuse to integrate unsigned or unverifiable work:
git merge --verify-signatures feature/login
git pull --verify-signatures origin mainWith --verify-signatures, the merge stops if the tip commit of the branch being merged lacks a valid signature. A good signature from an uncertified key does not count as valid under GnuPG's default trust model, so you must certify contributors' keys first. You can make this the default with git config merge.verifySignatures true.
This checks the branch tip, and the signature covers only that commit's own content. It does not prove that every earlier commit on the branch is signed. If you need that, inspect the whole range:
git log --pretty=format:"%h %G? %an %s" origin/main..feature/loginEdge cases
- Expired keys. Signature dates and key expiry interact. A commit signed while the key was valid is reported with status
XorYafter the expiry date, depending on whether the signature or the key expired. Extending a key's expiry date and republishing it makes old signatures verify cleanly again. - Email mismatch. GnuPG verifies against the key's user IDs, not against the commit's author field. A good signature from
[email protected]on a commit authored as Alice is still "good". Compare the signer (%GS) with the author yourself. - Subkeys. Git signs with a signing subkey. Verification still reports the primary key's identity, so you must have the whole public key, including subkeys, imported. A key exported before the subkey was added will produce "No public key".
- Signatures survive only unchanged objects. Amending, rebasing, or squashing creates a new commit, which needs a new signature.
- The date is not proof. The "Signature made" time comes from the signer's clock. It is not a trusted timestamp.
Troubleshooting a failed verification
If gpg reports an unexpected state, test without Git:
git cat-file commit HEAD
gpg --list-keys 3AA5C34371567BD2The first command shows the raw commit, including the gpgsig header that holds the signature. The second tells you whether the key is in your keyring at all. If --list-keys finds nothing, import the key. If it finds the key but shows [ unknown], certify it.
Exercise
You run git verify-commit HEAD on a contributor's commit and see Good signature from "Dana <[email protected]>" [unknown] followed by WARNING: This key is not certified with a trusted signature!. What does this tell you, and what are the steps to resolve it properly?
Show answer
The commit content matches the signature, so the commit was made by whoever holds that key. GnuPG has no evidence the key belongs to the real Dana, which is why validity is unknown. To resolve it, obtain Dana's full fingerprint through a trusted channel and compare it with gpg --fingerprint [email protected]. If they match, certify the key with gpg --lsign-key <fingerprint>. Running git verify-commit HEAD again should then show a validity of [full]. Setting owner trust or ultimate trust is not required for this.
Exercise
What do the %G? letters G, U, and E mean in git log --pretty=format:"%h %G? %s", and which would you accept in an automated merge check?
Show answer
G is a good signature with a valid key. U is a good signature whose key validity is unknown (uncertified). E means the signature could not be checked, for example because the public key is missing. A strict check should accept only G. Accepting U means trusting anyone who can create a key with the right name.