简体   繁体   English

`ssh -T` 到 VSTS(Azure Devops) 认证成功,但 `git clone` 失败

[英]`ssh -T` to VSTS(Azure Devops) authenticates successfully, but `git clone` fails

I recently created a second key to access Visual Studio Team Services,我最近创建了第二个密钥来访问 Visual Studio Team Services,

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

so I now have two keys:所以我现在有两个键:

id_github
id_vsts

Both keys seem to have been picked up by ssh: ssh-add -l lists both of them. ssh 似乎已获取了两个密钥: ssh-add -l列出了它们。

Next, I added id_vsts.pub to my VSTS account security.接下来,我将id_vsts.pub添加到我的 VSTS 帐户安全性中。 The key was properly added because requesting SSH terminal access authenticates properly:正确添加了密钥,因为请求 SSH 终端访问正确地进行了身份验证:

Authentication for user with identifier "" was successful against account "my_account". 
Shell is not supported.

However, when I git clone ssh://[user]@[host]:22/[repo] , it fails!但是,当我git clone ssh://[user]@[host]:22/[repo] ,它失败了!

Your Git command did not succeed.
Details:
        Public key authentication failed.

In an unexpected turn of events, if I use id_github 's public key, the clone succeeds.出乎意料的是,如果我使用id_github的公钥,则克隆成功。 What's going on?这是怎么回事?

在我的情况下,将IdentitiesOnly yes添加到 VSO 主机的~/.ssh/config文件就可以了。

You need to force the client to use specific private key, otherwise it uses the default one.您需要强制客户端使用特定的私钥,否则使用默认私钥。

To check which private key file used for a host, you can run要检查主机使用的私钥文件,您可以运行

ssh -v [host(e.g. test@test.visualstudio.com)]

One way is that you can configure it in the config file.一种方法是您可以在配置文件中对其进行配置。 (My steps for windows) (我的 Windows 步骤)

  1. Run touch .ssh/config if there isn't config file in .ssh folder如果 .ssh 文件夹中没有配置文件,请运行touch .ssh/config
  2. Open config file打开配置文件

code:代码:

Host xx.visualstudio.com
  IdentityFile /c/Users/xx/.ssh/id_vsts
  1. Open new command line and run Git clone command打开新命令行并运行Git clone命令

Another way is that, you can run ssh -i /path/to/id_rsa user@server.nixcraft.com command.另一种方法是,您可以运行ssh -i /path/to/id_rsa user@server.nixcraft.com命令。

More information, you can refer to this article: Force SSH Client To Use Given Private Key (identity file)更多信息,可以参考这篇文章: Force SSH Client To Use Given Private Key (identity file)

Apparently git uses only the first key provided, if that fails, git clone fails.显然 git 只使用提供的第一个键,如果失败, git clone 失败。 My ssh config had a wildcard option with a key matching before the git key and therefore it did not work.我的 ssh 配置有一个通配符选项,在 git 密钥之前有一个密钥匹配,因此它不起作用。 After moving the git configuration to the top of .sss/config all is fine.将 git 配置移动到 .sss/config 的顶部后一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM