簡體   English   中英

嘗試在 WSL 上使用 gpg 在 git 上簽署提交但不起作用

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

我最近嘗試了 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 的其他問題最終都說了同樣的話,即設置全局變量。 有什么我忘記或出錯了嗎? 謝謝。

microsoft/WSL 問題 4029 中緊隨其后

但在那種情況下,它是:

我的密鑰有密碼,但沒有提示輸入密碼。

但后來我讀到了這個

第 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] 之后

按照以下網址設置簽名提交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 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. apply git commit -S -m "初始提交🚀🚀🚀🚀"
  2. git config --global commit.gpgsign true

gpg 未能簽署數據致命:未能寫入提交對象 [Git 2.10.0]

如果您使用 Kleopatra 在 Windows 中管理您的 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 環境中打開編輯器並在那里工作。 但是,我失去了簽署我的承諾的能力。 因此,上述解決方案允許我保留現有的工作流程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM