Sub topic 3
Verifying SSH-Signed Commits and Tags
Assume you know basic git log, git tag, and git config, and that Git 2.34 or later is installed. An SSH signature proves that the matching private key signed the object. It does not prove that the person controlled the account or that the change is safe.
Verify SSH signatures with allowed signers
An allowed signers file maps a trusted identity, called a principal, to a public key. Git compares the commit’s email with the principal and checks the signature against the key.
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 -1
git verify-commit HEADThe principal must normally match the commit’s committer email. Add one line for each trusted key. A successful cryptographic check is separate from deciding whether the key is trusted.
Get a Verified badge
Hosting platforms usually require you to add the public signing key in your account settings. For SSH signing, register the .pub file as a signing key, not only as an authentication key. The commit email must also be linked to the account. The platform then checks the signature, key registration, and email association before showing a Verified badge.
Passphrases, agents, and hardware keys
A passphrase protects the private key. An SSH agent caches an unlocked key so Git does not ask every time. Hardware-backed keys keep signing operations inside a security device, which reduces private-key exposure.
Rewriting signed history
Rebasing, amending, and squashing create new commit objects. Their old signatures do not carry over. Sign the replacement commits again:
git commit --amend -S
git rebase --exec 'git commit --amend --no-edit -S' mainExpiry, rotation, and revocation
Record when each key expires and keep a replacement key ready. Register the new public key before removing the old one. Revoke a compromised key immediately, update allowed signers files, and remove the revoked key from hosting platforms.
Troubleshoot common errors
failed to sign the data: check that the agent or pinentry program can prompt for the passphrase.gpg.ssh.allowedSignersFile needs to be configured: set the file path and ensure it is readable.- An untrusted result: compare the committer email and principal, then confirm the public key is exact.
- No Verified badge: check the registered key type, account email, and repository platform settings.
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-}"
ssh-add -l
git log --show-signature -1Exercise
Why does an amended commit need a new signature?
Show answer
Amending creates a new commit object, so the original signature covers the old object and cannot validate the replacement.