Search code examples
gitsshvisual-studio-codewindows-10bitbucket

VS Code / Bitbucket / SSH - Permission denied (publickey)


I'm trying to access bitbucket via ssh from vscode but always get permission denied (publickey).

SSH key(s) are located under ~\.ssh\, public key(s) are correctly setup in bitbucket/settings/security/sshkeys. The keys are tested and do work!

After booting, I can access my repository without problems from the windows command prompt and powershell but NOT from git bash or from vscode. Manually setting up ssh in git bash and starting vscode works though:

eval $(ssh-agent)
ssh-add /c/Users/username/.ssh/privatekey
code

My environment:

  • Windows 10 Enterprise (1803/17134.765)
  • Visual Studio Code (1.35.0)
  • git for windows (2.20.1.windows.1)
  • bitbucket via ssh
  • I think I'm using the ssh-agent that was introduced in one of the later Windows10 updates (not sure how to check, the windows ssh-agent service is running though).
  • my user folder (containing /.ssh) and the working copy of the repo are located on network drives

For me the problem boils down to one question: Why is vscode not using windows native, correctly setup ssh service and instead relying on git bash ssh agent?

Disclaimer: I spent hours reading threads about this topic and fiddling with settings. I suspect the problem to be related to the delayed deployment of network drives under Windows10 (a known issue). My windows group policy is set to wait for the network on boot/login.


Solution

  • Windows 10 allows using all default OpenSSH tools. However, git was throwing permission denied for every time when I tried to clone repositories from Github, Gitlab or Bitbucket over SSH. You need to perform a few tweaks to make it work.

    1. Make sure ssh-agent service enabled, or run in Powershell (as administrator):

    Get-Service -Name ssh-agent | Set-Service -StartupType Manual

    1. ssh-agent
    2. ssh-add
    3. git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe