gpt4 book ai didi

git - 对于使用 WSL2 签名的 git 提交,Windows 10 上的 Visual Studio Code 中没有 GPG 密码提示

转载 作者:行者123 更新时间:2023-12-04 00:16:31 24 4
gpt4 key购买 nike

从 Windows 10 在 WSL2 中提交代码时,我无法在 Visual Studio Code 中使用签名提交。
问题
Windows 10 中未显示密码提示,导致 git 因 error: gpg failed to sign the data 失败

设置
Windows 设置
带有 WSL2 和 Windows 终端的最新版 Windows 10。
Visual Studio Code 安装在 Windows 10 中,是最新版本 (1.48.0),包括最新的远程 WSL 扩展 (v0.44.4)。
我的代码在运行 Ubuntu 20.04 的 WSL2 中,所有软件包都已更新。
Visual Studio Code 是使用 WSL2 中的 code . 命令通过命令行打开的。
Git 设置
Git (2.25.1) 安装在 WSL2 中,全局配置如下:

[user]
name = My Name
email = my.email@example.com
signingkey = A1B2C3D4E5F67890
[commit]
gpgsign = true
git 存储库是使用 WSL2 中的命令行启动的。
GPG 设置
gnupg (2.2.19) 安装在 WSL2 中。
我有 ~/.gnupg/gpg.conf 设置
use-agent
default-key A1B2C3D4E5F67890
~/.gnupg/gpg-agent.conf
default-cache-ttl 34560000
max-cache-ttl 34560000
pinentry-program /usr/bin/pinentry-curses
还有我的 ~/.zprofile
export GPG_TTY=$(tty)
export GPG_AGENT_INFO=${HOME}/.gnupg/S.gpg-agent:0:1

工作原理
如果我在 Windows 终端的 WSL2 中运行 git commit,它会提示我输入密码。
┌────────────────────────────────────────────────────────────────┐
│ Please enter the passphrase to unlock the OpenPGP secret key: │
│ "My Name <my.email@example.com>" │
│ 4096-bit RSA key, ID A1B2C3D4E5F67890, │
│ created 2020-08-10. │
│ │
│ │
│ Passphrase: __________________________________________________ │
│ │
│ <OK> <Cancel> │
└────────────────────────────────────────────────────────────────┘
然后,该密码短语会在我的 Windows session 的其余部分进行缓存,直到我重新启动笔记本电脑。此后的任何提交不再提示输入密码。
我现在可以使用 Visual Studio Code git UI 和 VSCode 的内置终端来提交更改。

问题
如果我重新启动我的笔记本电脑,那么在我第一次在 WSL2 中缓存 GPG 密码之前,来自 Visual Studio Code 的提交将不起作用。
也许值得注意,但如果我没有缓存密码并在 Visual Studio Code 中打开代码并尝试从内置 VSCode 终端进行提交,它也会失败。仅当首先通过 Windows 终端在 WSL2 中输入密码短语时才有效。
我很欣赏 Windows 10 和 WSL2 实际上是两个不同的系统,但是有什么方法可以让 Windows 为 WSL2 中运行的 git 显示 GPG 密码的提示?
还是我需要以完全不同的方式进行设置?我已经使用 MacOS 进行开发很长时间了,所以不确定 Windows 10 上的最佳路线可能是什么。
编辑:2020-08-17
我找到了 https://github.com/diablodale/pinentry-wsl-ps1 并将脚本用作 pinentry。当密码短语未缓存时,这会起作用并在 Windows 10 中显示 GUI。但我想找到一种不依赖于可能停止运行的脚本的解决方案。

最佳答案

我找到了一个解决方案......但在撰写本文时它有警告。
由于 Visual Studio Code 在 Windows 10 中运行并且 git & gpg 在 WSL2 中,我想在 Windows 10 端尝试一个可视化的 pinentry。
直到我订阅了 Windows Insider 的轨道并更新到最新的 Dev Build (2004 Build 20190.1000),这才起作用。
所需步骤:
加入 Windows Insider 计划并将 Windows 10 更新到 2004 Build 20190.1000(可能适用于早期版本,但这是我最先收到的版本)。这将为 WSL2 带来一些有趣的附加功能,增强互操作性——您现在还会注意到 Windows 资源管理器中的 Linux 选项。
https://www.gpg4win.org 安装 GPG4Win。除了默认的 gnupg 之外什么都不需要,但我也安装了 Kleopatra,以防它在其他地方派上用场。
编辑 ~/.gnupg/gpg-agent.conf 并更改 pinentry

pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"
现在,当您被要求输入密码时,GPG GUI 就会出现。
我已经测试了重新启动机器以确保密码短语没有被缓存并且它适用于:
  • 从 WSL2 命令行提交
  • 使用 Visual Studio Code git UI 提交
  • 使用 Visual Studio Code 内置终端提交

  • 这符合我的要求,但很高兴听到是否有任何我可能没有考虑的部分。

    关于git - 对于使用 WSL2 签名的 git 提交,Windows 10 上的 Visual Studio Code 中没有 GPG 密码提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63440623/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com