简体   繁体   English

尝试在 WSL 上使用 gpg 在 git 上签署提交但不起作用

[英]Trying to sign commits on git using gpg on WSL but does not work

I have recently tried the Windows Subsystem for Linux lately and as I was attempting to sign my git commits with a recently generated GPG key it spewed out,我最近尝试了 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

I have used git long enough to know that I have to set the local or global variables on git to use my GPG key.我已经使用 git 足够长的时间了,我知道我必须在 git 上设置本地或全局变量才能使用我的 GPG 密钥。

After the first error, I tried to generate another key but that also did not work, including the subkeys.在第一个错误之后,我尝试生成另一个密钥,但这也不起作用,包括子密钥。

My GPGs were encrypted in RSA and RSA (default).我的 GPG 是用 RSA 和 RSA 加密的(默认)。

I have tried using articles on help.github.com but to no avail.我曾尝试使用 help.github.com 上的文章,但无济于事。

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

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

Here is most of the terminal log这是大部分终端日志

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

Many sources online, as well as other questions on Stack Overflow, ended up saying the same thing, set the global variables.许多在线资源以及有关 Stack Overflow 的其他问题最终都说了同样的话,即设置全局变量。 Is there something I am forgetting or getting wrong?有什么我忘记或出错了吗? Thanks.谢谢。

That was followed in microsoft/WSL issue 4029microsoft/WSL 问题 4029 中紧随其后

But in that case, it was:但在那种情况下,它是:

My key has a passphrase but there is no prompt to enter the passphrase.我的密钥有密码,但没有提示输入密码。

But then I read this :但后来我读到了这个

Step 3 is export GPG_TTY=$(tty) , which sends the prompt to tty.第 3 步是export GPG_TTY=$(tty) ,它将提示发送到 tty。
After entering my passphrase, everything works.输入我的密码后,一切正常。

Example: danhorst/dotfiles commit 805a779 , which follows gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0] .示例: danhorst/dotfiles commit 805a779 ,它跟在gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0] 之后

Follow the below url to setup signed commit https://help.github.com/en/articles/telling-git-about-your-signing-key按照以下网址设置签名提交https://help.github.com/en/articles/telling-git-about-your-signing-key

if still getting gpg failed to sign the data fatal: failed to write commit object如果仍然得到 gpg 未能签署数据致命:未能写入提交对象

this is not issue with git ,this is with GPG follow below steps这不是 git 的问题,这是 GPG 的问题,请按照以下步骤操作

  1. gpg --version

  2. echo "test" | gpg --clearsign

if it is showing:如果它显示:

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

  2. then try again echo "test" | gpg --clearsign然后再试一次echo "test" | gpg --clearsign echo "test" | gpg --clearsign in which PGP signature is. echo "test" | gpg --clearsign其中 PGP 签名。

Output:输出:

-----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

Output:输出:

commit.gpgsign=true
gpg.program=gpg
tag.gpgsign=true
  1. apply git commit -S -m "initial commit 🚀🚀🚀🚀" apply git commit -S -m "初始提交🚀🚀🚀🚀"
  2. or git config --global commit.gpgsign truegit config --global commit.gpgsign true

gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0] gpg 未能签署数据致命:未能写入提交对象 [Git 2.10.0]

If you are using Kleopatra to manage your GPG keys in Windows, you can add the following to your ~/.gitconfig within your WSL environment (update your path accordingly):如果您使用 Kleopatra 在 Windows 中管理您的 GPG 密钥,您可以将以下内容添加到您的 WSL 环境中的 ~/.gitconfig (相应地更新您的路径):

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

After adding this, the prompt to enter my password for my GPG key appeared as usual.添加后,提示输入我的 GPG 密钥密码的提示照常出现。

Background: Using Docker had been extremely slow for me when using mounted volumes.背景:在使用挂载卷时,使用 Docker 对我来说非常慢。 I decided to just deploy the repository within an Ubuntu WSL environment directory (ie ~/projects/my_project) and up the containers from there using Docker WSL2 support.我决定只在 Ubuntu WSL 环境目录(即 ~/projects/my_project)中部署存储库,并使用 Docker WSL2 支持从那里部署容器。 I use Visual Studio Code so I could open the editor into the WSL environment directly and work from there.我使用 Visual Studio Code,因此我可以直接在 WSL 环境中打开编辑器并在那里工作。 However, I lost the ability to sign my commits.但是,我失去了签署我的承诺的能力。 Thus, the solution above allowed me to retain my existing workflow.因此,上述解决方案允许我保留现有的工作流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM