Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No secret key" error when signing git commit on Windows

Tags:

git

windows

gnupg

I'm getting this error when trying to sign a commit:

git commit -S -m "test"
gpg: skipped "EF617ACA9EC3XXXX": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

This is the output of gpg --list-secret-keys --keyid-format LONG

The key is present there

sec   rsa4096/EF617ACA9EC3XXXX 2020-05-17 [SC] [expires: 2022-05-17]
      AD68154000A712DCD161D826EF617ACA9EC3XXXX
uid                 [ultimate] name <[email protected]>

And this is git config with the same key

user.signingkey=EF617ACA9EC3XXXX
[email protected]

Any idea what's wrong?

like image 261
giveall Avatar asked May 17 '20 08:05

giveall


People also ask

What is commit signature in git?

You can sign commits locally using GPG, SSH, or S/MIME. Note: GitHub Desktop only supports commit signing if your Git client is configured to sign commits by default. Tips: To configure your Git client to sign commits by default for a local repository, in Git versions 2.0.

What is commit signing?

Signing, or code signing specifically, is the process of using cryptography to digitally add a signature to data. The receiver of the data can verify that the signature is authentic, and therefore must've come from the signatory. It's like physical signatures, but digital and more reliable.

How do I tell Git about my signing key?

If you have multiple keys or are attempting to sign commits or tags with a key that doesn't match your committer identity, you should tell Git about your signing key. If you're using GPG, after you create your commit, provide the passphrase you set up when you generated your GPG key. On GitHub, navigate to your pull request.

How do I sign all commits by default in Git?

Note: GitHub Desktop does not support commit signing. To configure your Git client to sign commits by default for a local repository, in Git versions 2.0.0 and above, run git config commit.gpgsign true. To sign all commits by default in any local repository on your computer, run git config --global commit.gpgsign true.

How do I Set my GPG signing key in Git?

From the list of GPG keys, copy the long form of the GPG key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2: To set your primary GPG signing key in Git, paste the text below, substituting in the GPG primary key ID you'd like to use. In this example, the GPG key ID is 3AA5C34371567BD2:

How do I sign a commit in GitHub desktop?

Note: GitHub Desktop does not support commit signing. To configure your Git client to sign commits by default for a local repository, in Git versions 2.0.0 and above, run git config commit.gpgsign true.


2 Answers

git config --global gpg.program "c:/Program Files (x86)/GnuPG/bin/gpg.exe"

I installed with Kleopatra and generated my key within that. I was unable to create a commit until I ran the command above.

like image 111
Eric Milliot-Martinez Avatar answered Oct 21 '22 06:10

Eric Milliot-Martinez


Check first the git config gpg.program to see if this is gpg or gpg2 (as in here).

And type where gpg nd where gpg2 to check which path is considered for the GPG program.

I suggested to set gpg.program to gpg2, and copy your gpg.exe (assuming its version is a 2.x) to gpg2.exe

That should force Git/GPG to act as gpg2.

like image 9
VonC Avatar answered Oct 21 '22 06:10

VonC