Signing commits in git uses wrong subkey

Viewed 2644

I have multiple signing subkeys on my main PGP key, so that I have one for my laptop, and one for my desktop. However, it seems like both computers try to use the key for my laptop, which was created more recently than the key for my desktop. I have user.signingkey set to the respective subkeys on both my laptop and desktop, but git still uses the one for my laptop.

2 Answers

Solution: KEYID must be appended with ! to use a specifc subkey.

eg.

git config --global user.signingkey A451BEC123\!

Many thanks to Todd Zullinger to provide the solution on Git mailing list.

Additional info

Double check that you are setting the global git config and not the repo config and check that you are supplying a signing key and not an encryption key.

Also, the output of git verify-commit HEAD will show the keyid of the master key instead of the subkey which could be misleading. To verify the commit is signed by subkey create a test signing subkey and sign a commit with it and revoke the subkey before and after checking signature with git verify-commit HEAD.

Display the key id of the keys on the machine and copy the id you want:

gpg --list-secret-keys --keyid-format LONG

Set your git configuration to use the specified key:

git config --global user.signingkey A451BEC123
Related