Vscode: Git: Support prompting for GPG password

Created on 16 Feb 2018  Â·  23Comments  Â·  Source: microsoft/vscode

  • VSCode Version: 1.19.3
  • OS Version: Windows 10

Hey, Git don't work in Visual Studio Code, when i have gpg signing activated.

Steps to reproduce: https://help.github.com/articles/signing-commits-with-gpg/

Does this issue occur when all extensions are disabled?: Yes

feature-request git help wanted

Most helpful comment

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@rugglcon, the following fixed it for me:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Now upon your first commit with VS Code, you should be prompted. Granted it's not a native VS Code prompt, but it makes everything work.

Source: https://stackoverflow.com/a/40066889

All 23 comments

It doesn't work if you use in gits default gpg feature, however, if you install Gpg4win and tell git to use that instead then it works.

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bingpg.exe"

@stevenhay Yes, but it's nice if visual studio supports it from his self(without any other applications)

Oh yeah I agree, definitely. Just thought I'd give a workaround for now though, I could have been more clear.

Solutions proposed here did not solve my problem.

Error :

gpg: cannot open tty `/dev/tty': No such device or address
error: gpg failed to sign the data
fatal: failed to write commit object

Configuration :

git config --global commit.gpgsign
true

cat ~/.gnupg/gpg-agent.conf
default-cache-ttl 46000
pinentry-program /usr/bin/pinentry-gtk-2
allow-preset-passphrase

If someone could shed some light on gpg-agent.conf, I'd like to know what settings are actually useful to sign my commits.

VSCode-Insiders :

{
    "git.enableCommitSigning": true,
}

OS :

neofetch --backend off
OS: Ubuntu 16.04.4 LTS x86_64 
Kernel: 4.13.0-39-generic 
Uptime: 17 hours, 15 mins 
Packages: 2984 
Shell: bash 4.3.48 
Resolution: 1024x768, 1920x1080 
DE: GNOME 3.18.5 
WM: GNOME Shell 
WM Theme: Adwaita 
Theme: Adwaita [GTK2/3] 
Icons: Elementary-xfce-dark [GTK2/3] 
CPU: Intel i5 660 (4) @ 2.895GHz 
GPU: NVIDIA GeForce 8400 GS Rev. 2 
Memory: 2452MiB / 7840MiB 

So... How do we GPG-sign our commits with VSCode?

@NahomAgidew For Ubuntu 18.04, it should be

pinentry-program /usr/bin/pinentry-gnome3

As can be seen with

ls -l /usr/bin/ | grep pinentry

But that does not seem to be enough.

_P.S. This issue is a dupe of https://github.com/Microsoft/vscode/issues/5065._

Thanks to @DrSensor, run this:

git config --global gpg.program $(which gpg)

Glad it helps :relaxed:

Seems it needs to be added in VSCode documentation. Just like this error, it should pop up a notification when the error gpg: cannot open tty '/dev/tty': No such device or address occur would be a great update for the next release 🙂

It would be nice if Visual Studio Code itself provided interactive passphrase prompts via the gpg-agent protocol. It's not an issue for a non-sandboxed installation, but it would help in Flatpak and Snap.

I've handled this already. You need to set git to call GPG auth from UI.
And then it will work for you.

On Wed, 31 Oct 2018, 5:04 pm Mikhail Zabaluev <[email protected]
wrote:

It would be nice if Visual Studio Code itself provided interactive
passphrase prompts via the gpg-agent protocol. It's not an issue for a
non-containerized installation, but it would help in Flatpak and Snap.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/43809#issuecomment-434720722,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARJfolAXDzQYhYx_KYLMk2vaMZYBX63ks5uqbwLgaJpZM4SH_zk
.

I've handled this already. You need to set git to call GPG auth from UI. And then it will work for you.

It does not when the gpg-agent socket is not forwarded into the app container.

.Try this config:

holms@debian ~/.aws> cat   ~/.gnupg/gpg-agent.conf 
default-cache-ttl 46000
pinentry-program /usr/bin/pinentry-gtk-2
allow-preset-passphrase

That's when I've got GUI auth window once committing to git from vscode. By default you've got cli auth, and then vscode doesn't nothing, once I've switch to pinentry-gtk-2 it started to work.

Don't forget to install pinentry :)

Hi @joaomoreno, any updates regarding this issue? I can't find a conculsive solution anywhere on GitHub or the internet :/

@plibither8 you need to gnome for this work or setup pinentry from my comment above

@holms, tried that, I'm still getting the following error:
image

Update: Solved this issue on my machine by configuring git to use gnupg2 instead of the regular gpg. Password is stored in the computer's password manager and I'm able to use VSCode's GUI to commit now.

Reference: https://askubuntu.com/a/805550

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@rugglcon, the following fixed it for me:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Now upon your first commit with VS Code, you should be prompted. Granted it's not a native VS Code prompt, but it makes everything work.

Source: https://stackoverflow.com/a/40066889

@bendwyer what I ended up doing (should have came back and updated my comment) was installing the GPG Keychain application for Mac, and they cache your password until your next reboot. So I commit once outside of VSCode to enter my pass phrase, then the rest of my commits I can do from Code.

Also just tried your way @bendwyer and can confirm it works as well.

Closing this since it's a matter of git configuration rather than VS Code.

@joaomoreno This issue is present in WSL sessions as well and I'm not sure if there's a workaround for it. I'm using gpg 2.2.4 on Ubuntu 18.04.4 on WSL. When I try to commit via VSC the first time, it fails. If I return to the terminal and run something silly to force passphrase prompt (such as echo "hello" | gpg --clearsign), enter that and return back to VSC to commit, it runs fine.

So, it'd be nice if the git integration could either show a dialog to take the passphrase and use that, or maybe even invoke an arbitrary command like above in the integrated terminal so that the user can enter their passphrase and retry the commit. Not sure what's the best approach since there can be different agents for the same but it'd be nice to support the popular/built-in ones and make this simpler.

Hi @sangeeth96 , I have the same idea, and I just wrote an extension to send passphrase to the gpg-agent.

If you don't mind 3rd party solution, you can give it a try. :D

Hi @sangeeth96 , I have the same idea, and I just wrote an extension to send passphrase to the gpg-agent.

If you don't mind 3rd party solution, you can give it a try. :D

hey @wdhongtw , I tried your extension on ubuntu 20.04 on wsl2 but it didn't seem to start up 😭 . I had the right settings on the local git config. Any ideas what might have happened?

Was this page helpful?
0 / 5 - 0 ratings