3

Because of this password prompt, auto-fetch, push and pull from VSCode doesn't work. This requires me to manually push/pull from the integrated terminal (which will prompt me a password).

However, when I run ssh -T git@github.com-work within the Integrated Terminal of VSCode, I am able to ssh in without a password prompt (which is what I am trying to achieve). I have already added the ssh keys via ssh-add and I see them using ssh-add -L. Similarly, I am able to run ssh -T git@github.com-work in Windows Terminal without being prompted for the password.

What I wish to achieve is being able to push and pull my repositories using VSCode's inbuilt tools without the password prompt every time I attempt to fetch, pull or push. This password prompt is preventing VSCode from auto-fetching or updating my repository by clicking the sync icon on the bottom right (results in a Permission denied(publickey, keyboard-interactive) prompt from VSCode)

Edit:

Thanks to VonC, I don't have to type my password everytime I run git fetch etc. within VSCode's integrated terminal. This was solved by adding

$env:GIT_SSH="C:\Windows\System32\OpenSSH\ssh.exe"

to my Powershell profile.

However, it still didn't resolve the main issue that VSCode's internal source control tools are unable to pull from git@github.com-work but keeps trying at git@github.com.

IcyBloom
  • 333
  • 2
  • 11

2 Answers2

1

Make sure the remote origin URL used by VSCode is actually github.com-work (check that in the VSCode output terminal for 'Git').
You don't even need git if your %USERPROFILE%\.ssh\config file does specify User git under the entry Host github.com-work)

And as mentioned here, launch VSCode (for testing) from a CMD where you have:

set GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hmm from VSCode output I can't really see the actual remote origin URL. All I see is ``` > git remote --verbose > git config --get commit.template > git fetch ``` however, I can verify on the side (I have Gitlens installed) that the remote is indeed `github.com-work`. However, it seems that VSCode is unable to understand that and keeps trying to pull from `github.com` instead – IcyBloom Dec 10 '20 at 08:06
  • 1
    @IcyBloom That is what I though. In command line, go to your local cloned repo, and type `git remote -v` to check. – VonC Dec 10 '20 at 08:09
  • Yeapp I just checked it and origins are both `git@github.com-work` for both fetch and push – IcyBloom Dec 10 '20 at 08:10
  • 1
    @IcyBloom Maybe that is VSCode translating your ssh config file. Or it actually uses another local repository path? – VonC Dec 10 '20 at 08:13
  • Hmm I don't think there is another local repository that can be used, and I have ensured that all my ssh config files are the same. :( Plus, through the integrated terminal it is able to git fetch and pull from the right remote, just not through the internal tools (that will output to the readonly terminal) – IcyBloom Dec 10 '20 at 08:18
  • @IcyBloom Does the issue persists for any repository accessed with an SSH URL? – VonC Dec 10 '20 at 08:33
  • Nope this issue only persists for repositories with a custom remote origin URL such as `git@github.com-work`. I have other personal local repositories using password protected SSH keys as well that uses the default remote URL `git@github.com`. My personal local repositories are able to pull and push through VSCode's tools without a problem – IcyBloom Dec 10 '20 at 08:35
1

These extra steps did the trick: ref

The key is to use Windows' OpenSSH as mentioned, but also need to setup git config file to load the key in the Windows Agent.

    AddKeysToAgent yes
    IdentitiesOnly yes
Efren
  • 4,003
  • 4
  • 33
  • 75