[英]Signing commits with Git doesn't ask for my passphrase
I was trying to sign my commits with the command git commit -S
but it fails without prompting my passphrase for my GPG key.我试图用命令git commit -S
来签署我的提交,但它失败了,没有提示我输入我的 GPG 密钥的密码。
The error is:错误是:
error: gpg failed to sign the data
fatal: failed to write commit object
I noticed that if I run the following command before git commit -S
:我注意到如果我在git commit -S
之前运行以下命令:
gpg -o /dev/null --local-user MY_KEY_ID -as <(echo 1234) && echo "The correct passphrase was entered for this key"
...everything works well and my commits are properly signed. ...一切正常,我的提交已正确签名。 I think it's because my passphrase is cached but this is not the behaviour that I expect.我认为这是因为我的密码被缓存了,但这不是我期望的行为。
I was hoping that Git would prompt for my passphrase everytime I want to sign commits or tags.我希望 Git 每次我想签署提交或标签时都会提示我输入密码。
The command to "unlock my key" was found on this question: How to use gpg command-line to check passphrase is correct在这个问题上找到了“解锁我的密钥”的命令: How to use gpg command-line to check passphrase is correct
You likely need to tell pinentry
, the software gpg uses to prompt for your password, where to prompt you. 您可能需要告诉pinentry
,gpg用来提示输入密码的软件以及提示您输入密码的位置。
export GPG_TTY=$(tty)
git commit -S
If this works I would recommend exporting GPG_TTY
in your shell's 'rc' file. 如果GPG_TTY
,我建议在您的Shell的rc文件中导出GPG_TTY
。
gpg-agent documentation regarding GPG_TTY
有关GPG_TTY
gpg-agent文档
For me, unsetting and setting again the signing key worked like a charm.对我来说,取消设置并再次设置签名密钥就像一个魅力。
This works either if you are changing the signing key for another one or git suddenly stopped prompting for the passphrase.如果您正在更改另一个签名密钥或 git 突然停止提示输入密码,这将起作用。
// remove signing key
git config --unset user.signingkey
// add new signing key
git config user.signingkey SECRETKEYLONGID
// tell git to automatically sign every commit
git config commit.gpgsign true
// commit as usual
git commit -m "commit message"
Git explains hot to get the signing key long ID. Git 说明热获取签名密钥长 ID。
That's it.. I hope it comes handy.就是这样..我希望它能派上用场。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.