Windows 10上的Visual Studio Code中没有GPG密码短语提示,用于使用WSL2的已签名git提交 [英] No GPG passphrase prompt in Visual Studio Code on Windows 10 for signed git commits using WSL2

查看:147
本文介绍了Windows 10上的Visual Studio Code中没有GPG密码短语提示,用于使用WSL2的已签名git提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Windows 10在WSL2中提交代码时,我无法在Visual Studio Code中使用已签名的提交.

I am unable to use signed commits within Visual Studio Code when committing code in WSL2 from Windows 10.

问题

在Windows 10中没有显示密码提示,导致git失败并出现错误:gpg无法对数据签名

No passphrase prompt is shown within Windows 10 resulting in git failing with error: gpg failed to sign the data

设置

Windows设置

具有WSL2和Windows Terminal的Windows 10的最新版本.

Latest version of Windows 10 with WSL2 and Windows Terminal.

Visual Studio Code已安装在Windows 10中,并且是最新版本(1.48.0),并包括最新的Remote WSL扩展(v0.44.4).

Visual Studio Code is installed within Windows 10 and is the latest version (1.48.0) and includes the latest Remote WSL Extension (v0.44.4).

我的代码在运行Ubuntu 20.04的WSL2中,所有软件包均已更新.

My code is within WSL2 running Ubuntu 20.04 with all packages updated.

在WSL2中使用 code.命令通过命令行打开Visual Studio代码.

Visual Studio Code is opened via the command line using the code . command from within WSL2.

Git设置

Git(2.25.1)通过以下全局配置安装在WSL2中:

Git (2.25.1) is installed within WSL2 with the following global config:

[user]
    name = My Name
    email = my.email@example.com
    signingkey = A1B2C3D4E5F67890
[commit]
    gpgsign = true

git库是使用WSL2中的命令行启动的.

The git repository is initiated using the command line within WSL2.

GPG设置

gnupg(2.2.19)已安装在WSL2中.

gnupg (2.2.19) is installed within 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 ,它会提示我输入密码.

If I run a git commit from within WSL2 in Windows Terminal it prompts me for my passphrase.

┌────────────────────────────────────────────────────────────────┐
│ 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会话的其余部分中缓存,直到我重新启动笔记本电脑为止.此后的任何提交都不再提示输入密码.

This passphrase is then cached for the rest of my Windows session until I restart my laptop. Any commit after this no longer prompts for the passphrase.

我现在能够使用Visual Studio Code git UI和VSCode的内置终端来提交更改.

I am now able to use the Visual Studio Code git UI and VSCode's built-in terminal to commit changes.

问题

如果我重新启动笔记本电脑,则直到我首先在WSL2中缓存GPG密码后,从Visual Studio Code提交的提交才起作用.

If I restart my laptop then commits from Visual Studio Code do not work until I first cache the GPG passphrase within WSL2.

也许值得注意,但是如果我还没有缓存密码短语并在Visual Studio Code中打开代码,并尝试从内置的VSCode终端进行提交,它也会失败.仅当通过Windows Terminal在WSL2中首先输入密码时,该功能才起作用.

Maybe worth noting, but if I haven't cached the passphrase and open the code within Visual Studio Code and try to do a commit from the built-in VSCode terminal it also fails. It only works if the passphrase is first entered within WSL2 via Windows Terminal.

我很欣赏Windows 10和WSL2实际上是两个不同的系统,但是有什么方法可以让Windows显示在WSL2中运行的git的GPG密码提示吗?

I appreciate that Windows 10 and WSL2 are really two different systems but is there any way to get Windows to display a prompt for the GPG passphrase for git running in WSL2?

还是我需要完全不同地进行设置?我已经使用MacOS开发了很长时间了,所以不确定在Windows 10上最好的选择是什么.

Or do I need to set things up completely differently? I've used MacOS for development for a long time now so not sure what the best route may be on Windows 10.

2020-08-17 我发现 https://github.com/diablodale/pinentry-wsl-ps1 和使用脚本作为对象.当密码短语未缓存时,这可以工作并显示Windows 10中的GUI.但我想找到一种不依赖可能会停止运行的脚本的解决方案.

2020-08-17 I found https://github.com/diablodale/pinentry-wsl-ps1 and used the script as the pinentry. This works and shows a GUI in Windows 10 when the passphrase isn't cached. But I'd like to find a solution that doesn't rely on a script that may stop functioning.

推荐答案

我找到了一个解决方案...但是在撰写本文时有一些警告.

I found a solution...but it has caveats at the time of writing.

由于Visual Studio Code在Windows 10和git&中运行我想尝试在Windows 10方面尝试视觉上的细化,gpg在WSL2中.

Since Visual Studio Code is running in Windows 10 and git & gpg are within WSL2 I thought of trying a visual pinentry on the Windows 10 side.

直到我订阅了Windows Insider的曲目并更新到最新的Dev Build(2004 Build 20190.1000)后,此方法才起作用.

This didn't work until I subscribed to the Windows Insider's track and updated to the latest Dev Build (2004 Build 20190.1000).

所需步骤:

加入Windows Insider程序并将Windows 10更新到2004 Build 20190.1000(可以在较早的版本上运行,但这是我首先收到的版本).这将为WSL2带来一些有趣的附加功能,并具有增强的互操作性-您现在还会注意到Windows资源管理器中的Linux选项.

Join the Windows Insider program and update Windows 10 to the 2004 Build 20190.1000 (might work on earlier builds but that's the one I received first). This will come with some interesting extras for WSL2 with increased interoperability - you'll also notice a Linux option in Windows Explorer now.

https://www.gpg4win.org 安装GPG4Win.除了默认的gnupg之外,什么都不需要,但是我也安装了Kleopatra,以防其他地方派上用场.

Install GPG4Win from https://www.gpg4win.org. Nothing other than the default gnupg is required, but I installed Kleopatra too in case it came in handy elsewhere.

编辑〜/.gnupg/gpg-agent.conf 并更改固定位置

pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"

现在,当系统要求您输入密码时,将显示GPG GUI.

Now when you are asked for your passphrase the GPG GUI shows up.

我已经测试过重启机器的过程,以确保密码短语不被缓存,并且可以用于:

I have tested this restarting the machine to ensure the passphrase isn't cached and it works for:

  • 从WSL2命令行提交
  • 使用Visual Studio Code git UI提交
  • 使用Visual Studio Code内置终端提交

这符合我的要求,但很高兴听到我可能没有考虑的任何内容.

This meets my requirements but happy to hear if there are any bits I may have not considered.

这篇关于Windows 10上的Visual Studio Code中没有GPG密码短语提示,用于使用WSL2的已签名git提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆