将 GPG 签名的 Git 提交集成到 VSCode Dev Container (WSL2 Ubuntu v20)

2024-03-05

我使用的是 Windows 10WSL2(与运行Ubuntu v20) with VSCode.

我想将 GPG 签名的 Git Commit 发送至GitHub in VSCode 开发容器 https://code.visualstudio.com/docs/remote/create-dev-container.

我尝试使用如下设置:

  1. Install Gpg4win https://gpg4win.org/download.html在Windows中

  2. 安装包在WSL2

sudo apt-get install gpg gnupg gpg-agent socat
  1. Edit ~/.gnupg/gpg-agent.conf in WSL2如下:
default-cache-ttl 34560000
max-cache-ttl 34560000

pinentry-program /mnt/c/Program Files (x86)/Gpg4win/bin/pinentry.exe
  1. 杀死特工
gpgconf --kill gpg-agent
  1. 生成密钥WSL2
gpg --full-generate-key
  1. 列出其中的键WSL2
gpg --list-secret-keys --keyid-format=long

示例输出

-----------------------------------
sec   rsa4096/00EF4D3F22885E4B 2021-11-20 [SC]
      1234567890ABCDEF1234567890ABCDEF12345678
uid                 [ultimate] peter <pete[email protected] /cdn-cgi/l/email-protection>
ssb   rsa4096/ABC123D7FAA52318 2021-11-20 [E]
  1. 设置 git 配置WSL2,电子邮件与 GPG 密钥匹配。
git config --global user.email "[email protected] /cdn-cgi/l/email-protection"

git config --global user.name "peter"

git config --global user.signingkey 00EF4D3F22885E4B

git config --global commit.gpgsign true
  1. 导出密钥并导入Github.
gpg --armor --export 00EF4D3F22885E4B
  1. 当我使用下面的 CLI 提交代码时WSL2,会弹出一个窗口让我输入密码,我就可以成功提交代码。
git commit -S -m "test"

但是,我无法提交代码Dev Container instance出现以下错误:

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

我怎样才能提交代码Dev Container instance? Thanks


您的更改可能已经生效,因为您重建了容器。由于某种原因,重新启动进程不会应用某些更改,但重建容器会应用某些更改。 VSCode 文档说要安装 gnugp2,我已安装它并执行了以下步骤:

https://code.visualstudio.com/docs/devcontainers/containers#_sharing-gpg-keys https://code.visualstudio.com/docs/devcontainers/containers#_sharing-gpg-keys

e.g. apt-get update && apt-get install gnupg2 -y

Then -

git config --global gpg.program "c:/Program Files (x86)/GnuPG/bin/gpg.exe"

我在其他地方看到的一些其他回复在 Windows 中设置 GPG 程序,如下所示:

git config --global gpg.program gpg

创建Windows系统环境变量:gpg = "c:/Program Files (x86)/GnuPG/bin/gpg.exe"

Then -

在 VSCode 设置中启用提交登录 通过 GUI 或在 settings.json 中:"git.enableCommitSigning": true

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 GPG 签名的 Git 提交集成到 VSCode Dev Container (WSL2 Ubuntu v20) 的相关文章

随机推荐