14

When I want to use git on with azure devops (vsts) I can't use git clone, pull, push etc. I get the error:

remote: remote: Your Git command did not succeed. remote: Details: remote: Public key authentication failed. remote: fatal: Could not read from remote repository.

But when I use the command below it works, so the problem is not the key. ssh-agent sh -c 'ssh-add ~/.ssh/key; git push repo'

When I do a git clone, push, pull etc I thought it goes through your .ssh dir to automatically check which key to use. Anybody any idea on how to fix this?

bramvdk
  • 1,347
  • 4
  • 21
  • 31
  • I'm seeing a similar thread at [developercommunity](https://developercommunity.visualstudio.com/content/problem/145027/cannot-do-git-operations-public-key-denied.html) which indicates this bug is fixed – Jayendran Oct 08 '18 at 07:52
  • check this question: https://stackoverflow.com/questions/42705553/ssh-t-to-vsts-authenticates-successfully-but-git-clone-fails – Shayki Abramczyk Oct 08 '18 at 08:17
  • 2
    look at the official doc [I have multiple SSH keys. How do I use different SSH keys for different SSH servers or repos?](https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops&tabs=current-page#q-i-have-multiple-ssh-keys--how-do-i-use-different-ssh-keys-for-different-ssh-servers-or-repos) – vladimir May 06 '20 at 09:34

5 Answers5

26

Fixed it by creating ~/.ssh/config and added:

Host xxx.visualstudio.com
  IdentityFile ~/.ssh/key

Make sure to do chmod 0400 ~/.ssh/config

bramvdk
  • 1,347
  • 4
  • 21
  • 31
  • 3
    look at the official doc [I have multiple SSH keys. How do I use different SSH keys for different SSH servers or repos?](https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops&tabs=current-page#q-i-have-multiple-ssh-keys--how-do-i-use-different-ssh-keys-for-different-ssh-servers-or-repos) – vladimir May 06 '20 at 09:33
13

I added in the ~/.ssh/config:

Host ssh.dev.azure.com
  IdentityFile ~/.ssh/[you private key file]
Lolorol
  • 533
  • 4
  • 11
4

My case was more tricky. VisualStudio.com banned my old ssh key and didn't bother to somehow notify me. Experimentally I figured out that I just need to add a new key and use it instead.

ssh-keygen -f ~/.ssh/new_key

In ~/.ssh/config:

Host vs-ssh.visualstudio.com
  IdentityFile ~/.ssh/new_key

That worked. Then fun thing was that they don't let you remove the old banned key from SSH Keys page.

Update: With OpenSSH 8.9p1 that makes ssh-rsa keys by default, you may need to enable ssh-rsa in ssh_config or ~/.ssh/config.

    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa

See https://stackoverflow.com/a/72102410/4653540

Yuri Pozniak
  • 667
  • 7
  • 11
3

I solved the problem by adding the identity to the SSH provider with

ssh-add [path to your private key]

so, for instance:

ssh-add /home/myuser/.ssh/id_rsa

Guildenstern70
  • 1,715
  • 18
  • 18
1

Along a similar line as Yuriy Pozniak's solution, I simply removed and re-added my public key, and that resolved my issue.

Modifying the ~/.ssh/config file to explicitly point the azure devops host to my private key did not work for me.

ivan
  • 11
  • 3
  • Thanks! Adding a new public key worked for me. This is really crazy. Last night I am able to connect from Debian machine and I wake up in the Morning and suddenly I can't push changes to the repository. If it's Micro$oft, it has to be crazy. – Kiran Mar 09 '21 at 04:14