我的~/.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 并打开了这两个项目。我 pull 了bitbucket。成功。 我在 azure 上进行了 pull 操作,但出现错误:远程:公钥身份验证失败。致命:无法从远程存储库读取。请确保您拥有正确的访问权限并且存储库存在。
然后我运行ssh -v MyAzureAlias
在调试中我得到debug1:身份文件/Users/myname/.ssh/id_rsa_azure_key
最后我得到了debug1:身份验证成功(公钥)。
这意味着我的 MyAzureAlias 的 ~/.ssh/config 工作正常。
然后我运行ssh-add -l,它给了我两个 key 。
然后我运行eval "$(ssh-agent -s)",然后再次运行ssh-add -l,但它没有给我任何 key 。 p>
然后我就跑了
- 评估“$(ssh-agent -s)”
- ssh-add -K ~/.ssh/id_rsa_azure_key
然后git pull成功。
配置:
- macOS Catalina 10.15.4。
- git 版本 2.24.1 (Apple Git-126)
- ssh -V OpenSSH_8.1p1、LibreSSL 2.7.3
如何解决这个问题?
提前谢谢您!
最佳答案
如果身份验证成功,但 Git 存储库访问失败(在 Azure 上),则需要仔细检查所使用的 URL。
应该是:
git ls-remote MyAzureAlias:<me>/<myrepo>
确保大小写(下/上)正确
关于如果之前没有在 Azure 上运行 ssh-add -K,Git pull 将无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61667372/