【问题标题】:Trying to sign commits on git using gpg on WSL but does not work尝试在 WSL 上使用 gpg 在 git 上签署提交,但不起作用
【发布时间】:2019-12-28 09:00:54
【问题描述】:

我最近尝试了适用于 Linux 的 Windows 子系统,当我尝试使用它喷出的最近生成的 GPG 密钥签署我的 git 提交时,

verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git commit -S -m "gpg signing"
error: gpg failed to sign the data
fatal: failed to write commit object

我使用 git 的时间足够长,知道我必须在 git 上设置本地或全局变量才能使用我的 GPG 密钥。

在第一个错误之后,我尝试生成另一个密钥,但也没有成功,包括子密钥。

我的 GPG 使用 RSA 和 RSA(默认)加密。

我曾尝试使用 help.github.com 上的文章,但无济于事。

(这里有一些具体的来源。) https://help.github.com/en/articles/telling-git-about-your-signing-key

https://help.github.com/en/articles/signing-commits

这里是大部分的终端日志

verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git config --global commit.gpgsign true
verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ gpg2 --list-secret-keys --keyid-format LONG
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: next trustdb check due at 2021-08-22
/home/verticalfile30/.gnupg/pubring.kbx
---------------------------------------
sec   rsa4096/498F47808959B459 2019-08-23 [SC] [expires: 2021-08-22]
      A533C851D2905FC63C161831498F47808959B459
uid                 [ultimate] Vert Simon (Key#3) <stopmotion45c@gmail.com>
ssb   rsa4096/E4E65BE559FFBE2C 2019-08-23 [E] [expires: 2021-08-22]

sec   rsa4096/B3C88EE54DC15CC9 2019-08-23 [SC]
      87F5399E6BFEF88C1C64794CB3C88EE54DC15CC9
uid                 [ultimate] Vert S (Sop) <stopmotion45c@gmail.com>
ssb   rsa4096/E868623210106F9D 2019-08-23 [E]

verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git config --global user.signingkey E868623210106F9D
verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git commit -S -m "gpg signing"
error: gpg failed to sign the data
fatal: failed to write commit object
verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git config --global user.signingkey B3C88EE54DC15CC9
verticalfile30@DESKTOP-U284V9I:~/cpo/wsltest$ git commit -S -m "gpg signing"
error: gpg failed to sign the data
fatal: failed to write commit object

网上的许多资源,以及关于 Stack Overflow 的其他问题,最后都说了同样的话,设置全局变量。 有什么我忘记或弄错了吗?谢谢。

【问题讨论】:

    标签: git github gnupg windows-subsystem-for-linux


    【解决方案1】:

    按照以下网址设置签名提交https://help.github.com/en/articles/telling-git-about-your-signing-key

    如果仍然得到 gpg 未能签署数据致命:未能写入提交对象

    这不是 git 的问题,这是 GPG 的问题,请按照以下步骤操作

    1. gpg --version

    2. echo "test" | gpg --clearsign

    如果显示:

    gpg: signing failed: Inappropriate ioctl for device
    gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device
    
    1. 然后使用export GPG_TTY=$(tty)

    2. 然后再试一次echo "test" | gpg --clearsign PGP 签名所在的位置。

    输出:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    test
    -----BEGIN PGP SIGNATURE-----
    
    iLMEAQEKAB0WIQS2V0SFHi18psvDbo7uFF+LP7qc1gUCYLjB2QAKCRDuFF+LP7qc
    1r5LBACB1m3Lpl21379qAvVamWcn9isdgdg34t34t43t34t34t434yGQHqikxWL7A5
    Ls7giKZYscb30o0rkY6I1W9MjBBW96R2pnaYsioFpsf434dfg54rfdgfdgdfgdfpaIoU3k
    JKrYxR7yMjqUv0a2jE+97kh+bSuzqwIkMHyikbABI90lY+4OLw==
    =UHKx
    -----END PGP SIGNATURE-----
    
    1. git config -l | grep gpg

    输出:

    commit.gpgsign=true
    gpg.program=gpg
    tag.gpgsign=true
    
    1. 应用 git commit -S -m "初始提交????"
    2. git config --global commit.gpgsign true

    gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

    【讨论】:

    • 虽然这解决了问题,但当我关闭终端并再次打开时,这个问题又回来了
    【解决方案2】:

    随后在microsoft/WSL issue 4029

    但在那种情况下,它是:

    我的密钥有密码,但没有提示输入密码。

    但后来我read this:

    第 3 步是export GPG_TTY=$(tty),它将提示发送到 tty。
    输入我的密码后,一切正常。

    示例:danhorst/dotfiles commit 805a779,紧随gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

    【讨论】:

    • 可以确认此解决方案在 Windows 11 中有效
    • @AbirTaheer Windows 11?!现在我必须检查是否可以运行:github.com/rcmaehl/WhyNotWin11
    【解决方案3】:

    如果您在 Windows 中使用 Kleopatra 管理您的 GPG 密钥,您可以将以下内容添加到 WSL 环境中的 ~/.gitconfig 中(相应地更新您的路径):

    [gpg]
        program = /mnt/c/Program Files (x86)/GnuPG/bin/gpg.exe
    

    添加后,输入GPG密钥密码的提示照常出现。

    背景:在使用挂载卷时,使用 Docker 对我来说非常慢。我决定只将存储库部署在 Ubuntu WSL 环境目录(即 ~/projects/my_project)中,并使用 Docker WSL2 支持从那里启动容器。我使用 Visual Studio Code,因此我可以直接将编辑器打开到 WSL 环境中并从那里开始工作。但是,我失去了签署我的承诺的能力。因此,上述解决方案允许我保留现有的工作流程。

    【讨论】:

    • 我一直试图让它工作一段时间。我在 Kleopatra 中生成了我的密钥,并试图在 WSL2 中签署提交。它正在使用 linux gpg 可执行文件并且无法正常工作。这让我可以在 WSL2 命令行上提交!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2019-07-30
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多