代码之家  ›  专栏  ›  技术社区  ›  PHPirate

gpg:keyblock resource pubring.kbx未找到,因为repo路径以gnupg home为前缀

  •  3
  • PHPirate  · 技术社区  · 7 年前

    我曾经让gpg签署我的承诺,这一切都很好,但我突然得到了这个信息:

    gpg: keyblock resource '/c/Users/username/path/to/project/C:\Users\username\.gnupg/pubring.kbx': No such file or directory
    gpg: skipped "my_key": No secret key
    gpg: signing failed: No secret key
    error: gpg failed to sign the data
    fatal: failed to write commit object
    

    注意keyblock资源的路径,它由两个路径组成,并且确实无效。

    我的提交自动签名,我的设置来自 this answer 总之:我像普通一样设置了gpg,然后安装了gpg2,每次使用shell文件都将我的密码短语导入gpg。不,我没有让gpg代理这么做,不过如果你知道怎么做,请回答这个问题: The key whose key-id is in the signature did not sign this commit

    GNUPGHOME 哪个指向 C:\Users\username\.gnupg . 我试着把它改成 C:/Users/username/.gnupg 但是斜杠在错误中也发生了变化。我试着把它改成 /c/Users/username/.gnupg 但是错误信息变成了

    gpg: Fatal: can't create directory '/c/Users/username/path/to/project/C:/Users/username/.gnupg': No such file or directory
    

    我也不知道是什么改变了我的系统,导致了这个问题。

    这个问题与另一条路径非常相似,但没有得到解决: Git commit signing GPG issue 注释是检查gitconfig中的路径,但是我在任何gitconfig中都没有gnupg目录的路径,而且我想它也不会以repo的路径作为前缀。我主要是这个 ~\.gitconfig :

    [user]
        signingkey = my_key
    [commit]
        gpgsign = true
    [gpg]
        program = C:\\Users\\username\\gpg-no-tty.sh
    

    在这里也发现有人有同样的问题: https://jira.atlassian.com/browse/SRCTREEWIN-8527

    我不知道这个问题是属于这里还是超级用户,因为我不确定这是编程还是直接使用(两者都是?)。

    2 回复  |  直到 7 年前
        1
  •  7
  •   Ross Newton    7 年前

    我也有同样的问题。为了解决这个问题,我只需要在.gitconfig文件中指定gpg.program变量来指向我安装的Gpg4win,如下所示:

    git config --global gpg.program "%PROGRAMFILES(x86)%\GnuPG\bin\gpg.exe"
    

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

    显然,路径取决于gpg二进制文件所在的位置。一旦我这样做了,它就能够使用GNUPGHOME环境变量并找到用于签名的系统密钥环。这将使用pinentry提示您输入密钥密码。

    希望这有帮助

        2
  •  1
  •   PHPirate    7 年前

    (请注意,我又遇到了同样的问题,但必须以不同的方式解决)

    你的gpg主目录是混乱的,因为那是它试图找到 pubring.kbx

    你可以用 --homedir gpg选项。

    1. 告诉bash使用它:在 C:\Users\username\.bash_profile ,添加 alias gpg="gpg --homedir=/c/Users/username/.gnupg"
    2. C:\Users\username\start-gpg.sh 把它放进去 gpg --homedir=/c/Users/s156757/.gnupg "$@" . 那就跑吧 git config --global gpg.program C:\\Users\\username\\start-gpg.sh
    3. 重新启动bash。

    注意:为了测试这一点,我使用了git附带的gpg2。这可能就是为什么GNUPGHOME变量没有做任何事情的原因——我没有单独安装gnupg。