3

I am trying to clone a repo from a project on my Team Foundation Server domain. I have created an SSH key under my profile security. However after accepting the repo's key I am still requested to sign in with a password and the authentication fails:

git clone ssh://mydomain@mydomain.visualstudio.com:22/Project/_git/project-repo
Cloning into 'project-repo'...
mydomain@mydomain.visualstudio.com's password: 
Permission denied, please try again.
mydomain@mydomain.visualstudio.com's password: 
Permission denied, please try again.
mydomain@mydomain.visualstudio.com's password: 
Permission denied (password,publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have tried both my visualstudio.com password and SHH key password none of which work.But Why is it asking me for a password?

HGB
  • 2,157
  • 8
  • 43
  • 74

3 Answers3

2

The prerequisite to use ssh for VSTS as below:

  1. Generate ssh key. In git bash, use ssh-kengen in git bash -> select path to save the key -> enter passphrase (if you don’t want passphrase, press enter direcly).
  2. Add the content of .ssh/id_rsa.pub file in KeyData in VSTS SSH public keys (profile -> security).

For your situation, it seems the conent of .ssh/id_rsa.pub is not same with VSTS SSH public keys. So you'd better do step1 and setp2 above and ten clone again with ssh protocol.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
2

The way I resolved this was by deleting and recreating my id_rsa.pub without a password.

HGB
  • 2,157
  • 8
  • 43
  • 74
0

The default authentication mode when using SSH is the private key. Whenever that fails for some reason, the ssh-agent falls back to username and password based authentication.

There are several reasons why the default key based authentication might have failed. Following are the most common cases :

a) The ssh-agent cannot find the default private key file which is id_rsa, and no other key path is specified explicitly.

b) The public key stored in the server is incorrect.

c) The path you're trying to clone is incorrect.

In any case, to troubleshoot the issue first of all execute the git clone command with verbose logging with the command :

GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone ssh://pathToYourRepo

You can go through each step in the log to get an intuition of what the issue might be.


Troubleshooting in case of (a)

  • Make sure you have the default key name id_rsa in the .ssh directory. You might have specified some different keyname when generating the key with ssh-keygen command or maybe there isn't any key at all).
  • In case you want to specify a different key for authentication, use the following command :

    ssh-agent bash -c 'ssh-add ~/.ssh/anotherKey; git clone ssh://pathToYourRepo'
    

Troubleshooting in case of (b)

  • Make sure there aren't extra white spaces when storing the public key in the server.

Troubleshooting in case of (c)

  • Make sure you aren't trying to clone with the https version of the repository path.
chaosifier
  • 2,666
  • 25
  • 39