Sub topic 9
Verifying SSH Signatures with an Allowed Signers File
This chapter assumes you have created an SSH signing key and set gpg.format to ssh, as covered earlier. It also assumes you know how git log and git config work.
Why SSH verification needs extra setup
GPG verification uses a keyring and a web of trust. SSH has neither. A signature only says that some private key signed the data. To decide whether that key belongs to a person you accept, Git needs a list of trusted keys. That list is the allowed signers file.
Without it, Git can still sign, but verification fails with an error like gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification.
The file format
Each line has a principal (usually an email address), optional options, and a public key. Git matches the principal against the committer email of the commit being checked.
[email protected] ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...
[email protected],[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...The namespaces="git" option limits the key to Git signatures. Git signs with the namespace git, so a key restricted this way cannot be used to validate signatures made for other purposes.
Set it up
This adds your own key and tells Git where the file is.
mkdir -p ~/.config/git
echo "[email protected] $(cat ~/.ssh/id_ed25519_signing.pub)" >> ~/.config/git/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
git log --show-signature -1A good result looks like this:
Good "git" signature for [email protected] with ED25519 key SHA256:Qx7...What Git checks
Two things must both match: the key must be listed, and the principal on that line must match the committer email. A valid signature from an unlisted key is not trusted.
Adding teammates
To verify a team's commits, collect each person's public key and add one line per key. Share the file through a repository or configuration management so everyone checks against the same list. Get each public key from its owner through a channel you trust, not from the commit being verified.
echo "[email protected] $(cat bob_signing.pub)" >> ~/.config/git/allowed_signers
git verify-commit HEADgit verify-commit exits with a non-zero status when verification fails, so you can use it in scripts and CI checks.
Common errors
| Message or symptom | Likely cause | Fix |
|---|---|---|
| `allowedSignersFile needs to be configured and exist` | Setting missing or path wrong | Set `gpg.ssh.allowedSignersFile` to an existing file |
| `No principal matched` | Committer email is not on any line | Add the email, or fix `user.email` for future commits |
| `Could not verify signature` | Key in the file differs from the signing key | Replace the line with the correct `.pub` content |
| Signature shows good locally but not on the host | Key not registered with the host | Upload the key as a signing key on the platform |
Exercise
A teammate's commit has a valid SSH signature, but git log --show-signature reports No principal matched. What is wrong, and how do you fix it?
Show answer
The committer email on the commit does not appear as a principal in the allowed signers file, so Git cannot match the key to an identity. Add a line with that email and the teammate's public key, or add the email to the existing line's comma-separated principal list.
Exercise
Why should you not copy a public key from the commit you are verifying into the allowed signers file?
Show answer
The file is the list of keys you trust. A key taken from the commit being checked only proves that whoever made the commit had that key, so it adds no trust. Get the key from its owner through a separate trusted channel.