【发布时间】:2020-12-05 23:39:45
【问题描述】:
从 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
使用 WSL2 中的命令行启动 git 存储库。
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 会话的其余部分缓存,直到我重新启动笔记本电脑。在此之后的任何提交都不再提示输入密码。
我现在可以使用 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。但我想找到一个不依赖可能停止运行的脚本的解决方案。
【问题讨论】:
标签: git visual-studio-code gnupg wsl-2