Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH Bitbucket Clone in Visual Studio 2019 not working

Cloning a bitbucket repo using Visual Studio 2019 not working. I am able to clone using command line but not using Visual Studio 2019 Git extension.

Command Line:

start-ssh-agent.cmd

then

git clone <ssh url>

This works fine in command line, but when trying to clone using Visual Studio 2019 (Default Git extension) I am getting this error.

enter image description here

Cloning works fine using gitbash command also.

$ eval ssh-agent -s

$ ssh-add id_rsa

VS git extension works fine for https urls but not using SSH urls.

I created key by following this link https://confluence.atlassian.com/bitbucketserver067/creating-ssh-keys-979426660.html and updated the key in bitbucket.

Any of you have encountered this issue or am I missing any steps here to configure VS 2019 to work for SSH Urls?

Thanks

like image 446
HashCoder Avatar asked Jan 27 '20 13:01

HashCoder


People also ask

How do I clone a Bitbucket repository in Visual Studio 2019?

In VS Code, select Clone a new copy from the dropdown menu. When prompted, select the local storage location where you want to keep the cloned repository. Select the Select repository location button. Your repository will be cloned and stored in the location you chose.

How do I clone a Bitbucket repository in Visual Studio using SSH?

Open visual studio and click on clone repo. You will be prompted with a window like this: Enter the copied SSH URL from your GitHub/Bitbucket repo. Please remember the path should start with git@.

How do I clone a repository in Visual Studio 2019?

Open Visual Studio 2019. On the start window, select Clone a repository. Enter or type the repository location, and then select Clone. You might be asked for your user sign-in information in the Git User Information dialog box.


2 Answers

I do not use Bitbucket with Visual Studio 2019, I use GitLab with Visual Studio 2019 via SSH. But I guess the procedure is the same.

I will explain you the structure I use in order to manage SSH keys used for GIT (Github, GitLab etc.). So far it always worked out for me, so maybe it does also for you:)

Search the folder %userprofile%/.ssh on your system and create a folder bitbucket.org in it. If you are not able to find the folder .ssh you can simply create one in %userprofile%. Copy the public and private ssh key into the newly created folder (bitbucket.org). The name of the file should be the same as your user name on bitbucket. The private ssh key should not have any file extension. The public ssh key should end in *.pub.

After having created the folder and copied all keys, you need to create a file config in %userprofile%/.ssh with the following content.

# Bitbucket
Host bitbucket.org
    Hostname bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/bitbucket.org/{username}

You have to substitute {username} with the correct file name.

Your folder structure should be the following:

  • %userprofile%/.ssh
    • bitbucket.org
      • username
      • username.pub
    • config

You may need to restart Visual Studio 2019 and all terminals.

HTH

like image 176
zanseb Avatar answered Oct 10 '22 21:10

zanseb


Check first your environment variables (active when you launch Visual Studio)

If you still have a GIT_SSH referencing plink, remove it (and relaunch VSCode): Recent Git for Windows should use OpenSSH by default.

Then, for testing, set a simplified %PATH%:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\cmd;%GH%\mingw64\bin;%PATH%

Generate a key without a passphrase (again, for testing), in that CMD session, using the old format.

ssh-keygen -m PEM -t rsa -P "" -f afile

If you are using the file by default (no -f parameter), that would be easier.
If not, you can setup a %USERPROFILE%/.ssh/config file as described here.

The OP HashCoder adds in the comments:

I generated the key using gitbash command line and add the key to ssh agent.
After this, I tried to clone using Visual Studio and worked.

like image 1
VonC Avatar answered Oct 10 '22 22:10

VonC