当我从Windows 10在WSL2中提交代码时,我无法在Visual Studio Code中使用签名提交。
问题
Windows 10没有显示密钥密码提示,导致git出现错误:error: gpg failed to sign the data
设置
Windows设置
最新版本的Windows 10,带有WSL2和Windows Terminal。
Visual Studio Code已安装在Windows 10中,并且是最新版本(1.48.0),包括最新的Remote WSL Extension(v0.44.4)。
我的代码位于运行Ubuntu 20.04的WSL2中,所有软件包已更新。
使用code .
命令从WSL2中打开Visual Studio 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 Terminal中的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界面和VSCode内置终端来提交更改。
问题
如果我重新启动笔记本电脑,那么来自Visual Studio Code的提交将无法工作,直到我首先在WSL2中缓存GPG密码。
也许值得注意的是,如果我没有缓存密码并尝试从内置的VSCode终端进行提交,则提交也会失败。只有在通过Windows Terminal首先在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。但我想找到一种不依赖可能停止功能的脚本的解决方案。
pinentry-program "/mnt/c/Program Files/Git/usr/bin/pinentry.exe"
也可以正常工作。 - Allan Chain