首页 > 解决方案 > 如果之前在 Azure 上运行 ssh-add -K,Git pull 将无法工作

问题描述

我的 ~/.ssh/config

Host MyAzureAlias
  HostName ssh.myhostname.azure.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_azure_key

Host MyBitbucketAlias
  HostName bitbucket.org
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa_bitbucket_key

然后我跑

ssh-add -K ~/.ssh/id_rsa_azure_key
ssh-add -K ~/.ssh/id_rsa_bitbucket_key

然后我打开了 webstorm 并打开了两个项目。我拉了bitbucket。成功。我在 azure 上进行了拉动,但出现错误:远程:公钥身份验证失败。致命:无法从远程存储库中读取。请确保您具有正确的访问权限并且存储库存在。

然后我运行ssh -v MyAzureAlias

在调试中我得到了debug1: identity file /Users/myname/.ssh/id_rsa_azure_key

最后我得到了debug1: Authentication succeeded (publickey)。

这意味着我的 ~/.ssh/config for MyAzureAlias工作正常。

然后我运行ssh-add -l它给了我两把钥匙。

然后我运行eval "$(ssh-agent -s)"然后我再次运行ssh-add -l它没有给我任何密钥。

然后我跑

然后git pull成功。

配置:

如何解决这个问题?

先感谢您!

标签: gitazuresshssh-agentssh-config

解决方案


如果身份验证成功,但 Git 存储库访问失败(在 Azure 上),则需要仔细检查使用的 URL。

它应该是:

git ls-remote MyAzureAlias:<me>/<myrepo>

确保大小写(小写/大写)正确


推荐阅读