Security

How to Verify a GPG Signature (gpg --verify, With Real Output)

To verify a GPG signature, import the publisher's public key, then run gpg --verify file.tar.gz.asc file.tar.gz with the signature first and the downloaded file second. A result of Good signature means the file is unmodified since it was signed by that key; you still have to confirm the key's fingerprint belongs to the real publisher.

All output below is real, produced with GnuPG 2.4.5 using a throwaway test key ("Alex Example") in a temporary keyring. Your key IDs, names and dates will differ.

What you need

  • The file you downloaded, for example app-1.0.tar.gz.
  • The detached signature, usually the same name plus .asc or .sig.
  • The publisher's public key, from the project's own site (often a KEYS file) or a keyserver.
  • gpg. On Linux it's normally preinstalled. On macOS install GnuPG with a package manager. On Windows, Gpg4win installs it, and Git for Windows also ships gpg inside Git Bash.

Step 1: import the public key

gpg --import alex.pub.asc

Example output:

gpg: key 8ECEB839D5DB4519: public key "Alex Example <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

The Apache Software Foundation, which signs every release, says the best source for a project's key is the project's own KEYS file, and that a key fetched from a public keyserver must be validated before you rely on it. Anyone can upload a key with any name on it.

To look at a key file before importing it, use gpg --show-keys, which prints it without adding it to your keyring:

gpg --show-keys --with-fingerprint alex.pub.asc
pub   ed25519 2026-10-26 [SC]
      510E 66C2 E561 B3D3 E5D6  55AB 8ECE B839 D5DB 4519
uid                      Alex Example <[email protected]>

Step 2: run gpg --verify

gpg --verify app-1.0.tar.gz.asc app-1.0.tar.gz

Example output:

gpg: Signature made Mon Oct 26 13:58:55 2026 FLEST
gpg:                using EDDSA key 510E66C2E561B3D3E5D655AB8ECEB839D5DB4519
gpg: Good signature from "Alex Example <[email protected]>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 510E 66C2 E561 B3D3 E5D6  55AB 8ECE B839 D5DB 4519

Always give both files, signature first. The GnuPG manual calls the one-argument form for detached signatures a "historical feature" whose use "is strongly discouraged": gpg would have to guess the data file's name. In batch mode it doesn't guess at all, and you get gpg: no signed data followed by gpg: can't hash datafile: No data.

Step 3: read the result

OutputExit codeMeaningWhat to do
Good signature from ...0The file matches what the key's owner signedCheck the fingerprint (step 4)
BAD signature from ...1The file or signature was changed after signingDon't use the file; download it again from the official source
Can't check signature: No public key2You don't have the signing keyImport the key whose ID is shown on the using ... key line

The exit codes are what this GnuPG 2.4.5 run returned; check $? in a shell or $LASTEXITCODE in PowerShell. Here is the BAD case, produced by appending a single byte to the file:

gpg: Signature made Mon Oct 26 13:58:55 2026 FLEST
gpg:                using EDDSA key 510E66C2E561B3D3E5D655AB8ECEB839D5DB4519
gpg: BAD signature from "Alex Example <[email protected]>" [unknown]

And the missing-key case, from a keyring that hasn't imported the key yet:

gpg: Signature made Mon Oct 26 13:58:55 2026 FLEST
gpg:                using EDDSA key 510E66C2E561B3D3E5D655AB8ECEB839D5DB4519
gpg: Can't check signature: No public key

A one-byte change is enough to turn Good into BAD. That's the point: the signature covers a cryptographic hash of the whole file, and the hash changes completely when any bit changes.

Step 4: check the fingerprint

The WARNING: This key is not certified with a trusted signature! line does not mean the check failed. It means gpg has no evidence that the key really belongs to the person named on it. As Apache's guide puts it, a good signature proves the file wasn't tampered with, and "the crucial step to validation is to confirm the key fingerprint of the public key."

Compare the 40-character Primary key fingerprint with one published somewhere an attacker would also have to compromise: the project's website over HTTPS, its documentation, a release announcement, or the developer in person. Compare the whole fingerprint, not just the last 8 or 16 characters.

If you have a key pair of your own, you can record the check so the warning disappears for this key: gpg --lsign-key followed by the fingerprint creates a local signature that stays on your machine and is never exported. Without a key of your own it fails with gpg: no default secret key: No secret key. That's fine: the warning is informational, and once you've compared the fingerprint you can leave it.

Verifying in scripts

Don't grep for "Good signature" in a script. Check the exit code, and pin the expected key. GnuPG 2.4 has --assert-signer, which makes gpg fail unless the signature was made by the fingerprint you give:

gpg --assert-signer 510E66C2E561B3D3E5D655AB8ECEB839D5DB4519 --verify app-1.0.tar.gz.asc app-1.0.tar.gz

This is a real trap: when we passed a different fingerprint, gpg still printed Good signature from "Alex Example", because the signature is mathematically valid, but exited with status 1 because the signer didn't match. Anything reading only the text would have accepted it. For machine-readable results, --status-fd 1 prints status lines such as [GNUPG:] GOODSIG and [GNUPG:] VALIDSIG followed by the full fingerprint. The manual also points to gpgv, a stripped-down verifier that succeeds only for a good signature from keys in a keyring you specify.

Signed checksum files (SHA256SUMS.asc)

Many projects sign one checksum file instead of every download. The flow is two steps: verify the signature on the checksum file, then check your download against it.

gpg --verify SHA256SUMS.asc SHA256SUMS
sha256sum --ignore-missing -c SHA256SUMS

On Windows without sha256sum, run Get-FileHash .\app-1.0.tar.gz -Algorithm SHA256 and compare it with the line in the file, or use the browser-based checksum tool. Some projects publish a cleartext-signed file instead, where the checksums and signature are in one .asc; verify it with just gpg --verify SHA256SUMS.asc. If a file called SHA256SUMS also sits in the same folder, gpg 2.4.5 adds gpg: WARNING: not a detached signature; file 'SHA256SUMS' was NOT verified!: the checksums inside the .asc were verified, the separate file next to it was not, so read the hashes from the .asc. The GnuPG manual notes that gpg only vouches for the signed block, not text around it, and recommends detached signatures over cleartext ones.

Why this works

OpenPGP, the format gpg implements (currently specified in RFC 9580), creates a signature by hashing the file and signing that digest with the signer's private key. To verify, gpg hashes the file you downloaded and checks the result against the signature using the public key. Anyone with the public key can check it, but only the private key holder can produce it. The public-key cryptography explainer walks through the maths with small numbers.

That also shows the limit. The signature proves "the holder of this key signed this exact file". Whether that key holder is the real project is what the fingerprint check in step 4 establishes, and it's the step people skip.

Frequently asked questions

What is the difference between a .asc and a .sig file?
Both are usually detached signatures and are verified the same way with gpg --verify. A .asc file is ASCII-armored, so it is plain text starting with -----BEGIN PGP SIGNATURE-----. A .sig file is normally the same signature in binary form. gpg detects which one it is automatically.
Is a checksum enough instead of a signature?
A checksum only proves the file matches the checksum you compared it with. If an attacker can replace the download, they can usually replace the checksum file on the same server too. A signature ties the file to a private key the attacker does not have. Many projects sign the checksum file, so you verify the signature on SHA256SUMS once and then check each download against it.
How do I get rid of the 'This key is not certified with a trusted signature' warning?
The warning means you have not told gpg that this key belongs to its owner. After confirming the fingerprint through an independent channel, you can sign the key locally with gpg --lsign-key followed by the fingerprint, which needs a key pair of your own and marks the key as verified on your machine only. If you have no key of your own, simply leave the warning: the signature check is already complete when gpg prints Good signature.
Why does gpg say 'no signed data' or 'can't hash datafile'?
You passed only the signature file. With a detached signature, gpg needs the signature first and the data file second, for example gpg --verify app.tar.gz.asc app.tar.gz. The GnuPG manual strongly discourages relying on gpg to guess the data file name from the signature name.

Sources