I am using Git from the VS Code terminal on Ubuntu. For some reason, it started to ask me to unlock my SSH key every time I wanted to push/pull. Here are a few things to try first:
- This is usually fixed by configuring the SSH agent, for instance as explained here in the VS Code documentation.
- If you are using Zsh, you can also configure the SSH agent with a plugin, such as this one for Oh My Zsh or this one for Zim. It takes only one line in your
.zshrc
and asks for the password only once.
The issue is that none of the usual methods worked for me. After trying countless hacks and tricks, I finally came up with a solution: I just needed to talk to the Gnome Keyring daemon instead of ssh-agent
. My setup might be oddly specific, but in case it can save your time, fellow Internet wanderer, here is my workaround.
Just add the following snippet in your .zshenv
or .bash_profile
:
if [ -z "$DESKTOP_SESSION" ];then
eval $(gnome-keyring-daemon --start)
export SSH_AUTH_SOCK
fi
Edit: I used this with Gnome Keyring version 3.36 and 40.0. It seems that newer (42+) versions don’t require this workaround anymore and can use a service instead.