Sub topic 9
Verifying SSH Signatures with an Allowed Signers File
This chapter assumes you can already sign a commit with an SSH key (gpg.format ssh, user.signingkey, commit.gpgsign), and that you know the difference between a public and a private key. It covers how Git checks an SSH signature locally, the format of the allowed signers file, and the errors you will meet most often.
Why SSH verification needs extra setup
With GPG, a signature carries a key ID. Git asks GnuPG to look that ID up in your keyring and report whether the key is trusted. SSH has no keyring of this kind. An SSH signature embeds the signer's public key, so the signature is self-consistent on its own. That only shows that some key made the signature. It does not show that the key belongs to someone you trust.
Git therefore needs a separate list of keys you accept. That list is the allowed signers file. Git passes it to ssh-keygen -Y verify, which does the actual check.
| Question | GPG | SSH |
|---|---|---|
| Where does Git find trusted keys? | GnuPG keyring and its trust model | File named by `gpg.ssh.allowedSignersFile` |
| What decides "trusted"? | Web of trust, key validity, ownertrust | Whether the key is listed for that identity |
| What does Git run? | `gpg --verify` | `ssh-keygen -Y find-principals` and `-Y verify` |
The allowed signers file format
Each line has this shape:
principals [options] key-type base64-public-key [comment]- principals is a comma-separated list of patterns. Git compares it with the committer email in the commit (for tags, the tagger email). Wildcards such as
*@example.comare allowed. - options are optional and comma-separated. The ones that matter here are
namespaces="git",valid-after, andvalid-before. - key-type and the key are the same two fields you find in a
.pubfile, for examplessh-ed25519 AAAA....
A realistic file for a small team:
[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyAliceExampleKeyAliceExampleKey
[email protected],[email protected] namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyBobExampleKeyBobExampleKeyBobX
*@ci.example.com namespaces="git" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyCIExampleKeyCIExampleKeyCIExampThe key text above is a placeholder. Use the full contents of your own .pub file.
Namespaces
SSH signatures are bound to a namespace, which stops a signature made for one purpose from being replayed for another. Git signs with the namespace git. Adding namespaces="git" to a line means that key is accepted only for Git signatures, not for other uses of ssh-keygen -Y sign. Always include it. Without it, a key you listed for Git could also validate signatures made for other tools that use the same file.
Setting it up
Build the file from your own public key and tell Git where it is:
mkdir -p ~/.config/git
echo "[email protected] namespaces=\"git\" $(cat ~/.ssh/id_ed25519_signing.pub)" >> ~/.config/git/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
git log --show-signature -1The .pub file may end with a comment such as [email protected]. That is harmless, because the comment field is allowed at the end of the line.
A successful check prints something like:
commit 4f2a9c1e7b0d...
Good "git" signature for [email protected] with ED25519 key SHA256:Qm3k...
Author: Alice <[email protected]>The principal in that line is the one from the allowed signers file that matched the key. The SHA256: value is the key fingerprint. You can compute the same value with ssh-keygen -lf ~/.ssh/id_ed25519_signing.pub.
Verification commands
The same commands work for both backends:
git log --show-signature -1
git verify-commit HEAD
git verify-commit --verbose HEAD
git tag -v v1.0.0
git verify-tag v1.0.0
git log --format='%h %G? %GS %GK' -5git verify-commit and git verify-tag exit with status 0 only if the signature is good. That makes them usable in scripts and CI jobs.
The last command prints the signature status per commit using format placeholders:
| Placeholder | Meaning |
|---|---|
| `%G?` | Status letter |
| `%GS` | Signer (the matched principal) |
| `%GK` | Key (fingerprint for SSH) |
| `%GF` | Fingerprint of the signing key |
Common %G? letters:
| 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` | Cannot be checked, for example a missing key |
| `N` | No signature |
For SSH, Git reports G when the key is in the allowed signers file and N or E-style failures otherwise. The "unknown validity" distinction mostly belongs to GPG's trust model.
Using one file for a team or repository
A per-user file in ~/.config/git works for one person. For a team, there are two common approaches.
- Commit the file to the repository. Put it at a path such as
.github/allowed_signersand have each developer point Git at it with a repository-local setting:
``bash git config gpg.ssh.allowedSignersFile .github/allowed_signers ``
Git does not read this setting from the repository by itself. Each clone must set it.
- Distribute a managed file. Configuration management or a dotfiles repository places the file on each machine.
Whichever you choose, treat changes to the file as security changes. Whoever can edit the file decides which keys are trusted. If the file lives in the same repository it protects, a malicious commit could add an attacker's key and then be signed by it. Review changes to the file, and verify it against a commit you already trust, for example the previous release tag.
Key validity windows
Options valid-after and valid-before limit when a key is accepted. Times use YYYYMMDD or YYYYMMDDHHMMSS format.
[email protected] namespaces="git",valid-before="20271231" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKeyAliceExampleKeyAliceExampleKeyA date check uses the time of verification, not the time recorded in the commit. The commit timestamp is set by the author and can be forged. Because of this, valid-before does not reliably tell you that a commit was made before the key was retired. It only stops new verifications after that date. To handle retired keys properly, see the chapter on expiry, rotation, and revocation.
Common errors
No principal matched
error: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verificationGit has no file to read. Set gpg.ssh.allowedSignersFile and make sure the path exists. A ~ in the config value is expanded by Git, but a relative path is resolved from the current directory, so prefer absolute paths for global settings.
Good "git" signature with ED25519 key SHA256:Qm3k...
No principal matched.or
No signatureThe signature is valid, but the key is not listed, or the email does not match. Check these in order:
- Compare the key fingerprint in the error with
ssh-keygen -lfoutput for each key in the file. - Compare the committer email (
git log -1 --format=%ce) with the principal. Note that this is the committer, not the author. - Check that the principal pattern is spelled the same way, including case.
- Check
namespaces. A line withnamespaces="other"does not match Git signatures.
Wrong key in `user.signingkey`
If user.signingkey points to a private key, Git can usually still sign through the agent, but be consistent. Use the .pub path, or key::ssh-ed25519 AAAA... for a literal key. If the key is only in an agent, the literal form is the safest.
Tabs, line breaks, and stray characters
The file is whitespace-separated. A key broken across two lines, or a line with Windows line endings, fails without a clear message. Check with:
ssh-keygen -Y find-principals -s sig.file -f ~/.config/git/allowed_signersYou can also test the file directly. Sign a file, then verify it:
echo "hello" > msg.txt
ssh-keygen -Y sign -f ~/.ssh/id_ed25519_signing -n git msg.txt
ssh-keygen -Y verify -f ~/.config/git/allowed_signers -I [email protected] -n git -s msg.txt.sig < msg.txtThe second command prints Good "git" signature for [email protected] with ED25519 key ... when the file and key match. This isolates file problems from Git problems.
Verification works for you but not on a colleague's machine
The allowed signers file is local. A colleague who has not listed your key sees no principal match, even if the commit shows as verified on the hosting site. The two systems keep separate lists.
What a good result tells you
A good SSH signature means the commit or tag content has not changed since signing, and it was signed by a key you listed for that email. It does not tell you the person is who they claim to be, that their machine was uncompromised, or that the commit is safe. The strength of the result depends on how carefully you maintain the file.
Exercise
A teammate's commit shows Good "git" signature with ED25519 key SHA256:Qm3k... followed by No principal matched. Their key is in your allowed signers file under [email protected]. Give two likely causes and one command to check each.
Show answer
First, the committer email may differ from the principal, for example the commit was made with [email protected]. Check with git log -1 --format=%ce. Second, the key in the file may not be the one used for signing, or the line may have a different namespaces value. Compare fingerprints with ssh-keygen -lf on the key from the file and check the line for namespaces="git". A broken line, such as a key split across two lines, is a third possibility.
Exercise
Why is valid-before in an allowed signers file not a reliable way to reject commits made with a stolen key after the theft?
Show answer
Git checks the date at verification time, not against a trusted record of when the commit was made. The commit timestamp is chosen by the author, so an attacker who has the key can set any date. The option only stops the key from validating after a given date. Rejecting such commits needs key removal or revocation plus a review of history.