Home > database >  Integration of GPG-signed Git commits in VSCode Dev Container (WSL2 Ubuntu v20)
Integration of GPG-signed Git commits in VSCode Dev Container (WSL2 Ubuntu v20)

Time:02-21

I am using Windows10 WSL2(running with Ubuntu v20) with VSCode.

I want to send GPG-signed Git Commit to GitHub in VSCode Dev Container.

I try with the setup like below:

  1. Install Gpg4win in Windows

  2. install packages in WSL2

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

pinentry-program /mnt/c/Program Files (x86)/Gpg4win/bin/pinentry.exe
  1. kill the agent
gpgconf --kill gpg-agent
  1. generate keys in WSL2
gpg --full-generate-key
  1. list the keys in WSL2
gpg --list-secret-keys --keyid-format=long

example output

-----------------------------------
sec   rsa4096/00EF4D3F22885E4B 2021-11-20 [SC]
      1234567890ABCDEF1234567890ABCDEF12345678
uid                 [ultimate] peter <[email protected]>
ssb   rsa4096/ABC123D7FAA52318 2021-11-20 [E]
  1. set git config in WSL2, email is matched with the GPG key.
git config --global user.email "[email protected]"

git config --global user.name "peter"

git config --global user.signingkey 00EF4D3F22885E4B

git config --global commit.gpgsign true
  1. export the keys and import in Github.
gpg --armor --export 00EF4D3F22885E4B
  1. When I commit the codes with CLI below in WSL2, there is a pop up for me enter the passphrase and I can commit the codes successfully.
git commit -S -m "test"

However, I cannot commit the codes in the Dev Container instance with the error below:

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

How can I commit the codes in Dev Container instance? Thanks

CodePudding user response:

It turns out I should not install gnupg2 in my Dev Container instance.

  • Related