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

ary*_*ing 6 git ssh azure-devops azure-pipelines

我最近创建了第二个访问Visual Studio Team Services的密钥,

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Run Code Online (Sandbox Code Playgroud)

所以我现在有两把钥匙:

id_github
id_vsts
Run Code Online (Sandbox Code Playgroud)

两个键似乎都被ssh选中了:ssh-add -l列出了它们.

接下来,我添加id_vsts.pub了我的VSTS帐户安全性.密钥已正确添加,因为请求SSH终端访问正确进行身份验证:

Authentication for user with identifier "" was successful against account "my_account". 
Shell is not supported.
Run Code Online (Sandbox Code Playgroud)

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

Your Git command did not succeed.
Details:
        Public key authentication failed.
Run Code Online (Sandbox Code Playgroud)

在一个意外的事件发生时,如果我使用id_github的公钥,克隆就会成功.这是怎么回事?

mar*_*s-O 7

就我而言,添加IdentitiesOnly yes~/.ssh/configVSO主机的文件就可以了.


sta*_*SFT 5

您需要强制客户端使用特定的私钥,否则它将使用默认的私钥。

要检查主机使用的私钥文件,可以运行

ssh -v [host(e.g. test@test.visualstudio.com)]
Run Code Online (Sandbox Code Playgroud)

一种方法是您可以在配置文件中对其进行配置。(我的Windows步骤)

  1. touch .ssh/config如果.ssh文件夹中没有配置文件,请运行
  2. 打开配置文件

码:

Host xx.visualstudio.com
  IdentityFile /c/Users/xx/.ssh/id_vsts
Run Code Online (Sandbox Code Playgroud)
  1. 打开新命令行并运行Git clone命令

另一种方法是,您可以运行ssh -i /path/to/id_rsa user@server.nixcraft.com命令。

有关更多信息,您可以参考本文:强制SSH客户端使用给定的私钥(身份文件)