关于 DreamCat

主题名称:DreamCat | 版本:3.0.240224

主题开发:HanFengA7 | CornWorld

Designed by HanFengA7 Power by Typecho

Copyright © 2015-2024 by LychApe All rights reserved!

menu
refresh

vscode 无法在 wsl 下使用 gpg 签名问题的解决方案

作者: scdhh

时间:

最近将开发环境都搬到了 wsl 上,配了一下 gpg,一开始 vscode commit 报错,然后手动在终端测试了一下 gpg
就正常了,后来重启了问题复现,研究了一下,顺便记录一下解决方法。

vscode 的报错:

error: gpg failed to sign the data
fatal: failed to write commit object

解决方法:

  1. 首先需要确保你的 wsl 版本是 2,因为我这个解决方案是用到了 wslg 的。
    可以输入 wsl --list -v 查看版本。
    如果 VERSION 是 1,可以运行 wsl --set-version <distro name> 2 参考微软文档
  2. sudo apt install kleopatra scdaemon
  3. sudo bash -c 'dbus-uuidgen > /var/lib/dbus/machine-id'

然后你可以尝试启动 kleopatra,如果出现报错类似👇

kf.dbusaddons: DBus session bus not found. To circumvent this problem try the following command (with bash):
export $(dbus-launch)

请运行 export $(dbus-launch) && echo -e '\nexport $(dbus-launch)' >> ~/.bashrc
tips:如果你是其他 shell 请自行添加 export $(dbus-launch) 到你的启动脚本

好了,到这里你的 vscode 应该可以使用 gpg 签名了。

如果你还是有问题,可以尝试在 ~/.gnupg/gpg-agent.conf 里添加 pinentry-program /usr/bin/pinentry
然后执行 gpg-connect-agent reloadagent /bye


然后这里是一些探索过程:

首先为什么 vscode 会报错呢?
因为 git 报错了。
那为什么 git 报错了呢。
因为 git 没办法调用 gpg 默认的 cli 让你输密码,如果你是在 shell 里运行的git 你应该会看到一个密码框,但是 vscode 的 git 不一样,它没有终端给它用。
那么我们就需要找一个 gui 程序给 gpg 输密码。
一开始我找到了这篇文章。

https://stackoverflow.com/questions/63440623/no-gpg-passphrase-prompt-in-visual-studio-code-on-windows-10-for-signed-git-comm

有一个解决方法是调用 Windows 的 pinentry.exe
我尝试过了,但是这对我来说没用。
经过一些排查之后,我发现在 shell 里也没办法调用 gpg 了。
gpg报错👇

gpg: 签名时失败: 缺少 pinentry
gpg: [stdin]: clear-sign failed: 缺少 pinentry

这就奇怪了,然后我去手动 call pinentry.exe。
然后报错👇

<3>WSL (1344) ERROR: UtilAcceptVsock:246: accept4 failed 110

搜索之后发现,在 2022 年 8 月 2 日 GitHub 就有了相关 issue
简单来说就是微软写 bug 了,子系统叫不起来 Windows 上的程序了。
我当时就

然后想起来我原来在 Windows 上用的 Kleopatra 也支持 Linux,一番尝试之后,就有了本文。

好,那么本文到此完结🎉 啪唧啪唧啪唧

info_icon
#本文链接:https://blog.xn--dtra.com/archives/7/
#本文采用 CC BY-NC-SA 4.0 协议进行许可
#如无特别声明,该文章均为 scdhh 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0)协议,即转载请注明文章来源。
#最后编辑时间为: 2023 年 02 月 12 日
create 添加新评论
account_circle
email
language
textsms
assessment 已有 3 条评论
  1. avatar
    2023-04-27 14:01

    找了一圈还是这个有用, 帮大忙了

    1. avatar
      2023-05-04 22:53

      能帮上忙就好🥰

  2. avatar
    2024-03-17 04:29

    真是太感谢辣!简洁准确,没有多余的废话!要是中文社区能多一些这样的分享,少一点机翻或者AI生成的水文就好了

加我的QQ
加我的微博
加我的支付宝
加我的微信