`ssh -T` 到 VSTS(Azure Devops) 认证成功,但 `git clone` 失败 [英] `ssh -T` to VSTS(Azure Devops) authenticates successfully, but `git clone` fails
问题描述
我最近创建了第二个密钥来访问 Visual Studio Team Services,
I recently created a second key to access Visual Studio Team Services,
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
所以我现在有两个键:
id_github
id_vsts
两个密钥似乎都被 ssh 获取了:ssh-add -l
列出了它们.
Both keys seem to have been picked up by ssh: ssh-add -l
lists both of them.
接下来,我将 id_vsts.pub
添加到我的 VSTS 帐户安全性中.密钥已正确添加,因为请求 SSH 终端访问权限正确:
Next, I added id_vsts.pub
to my VSTS account security. The key was properly added because requesting SSH terminal access authenticates properly:
Authentication for user with identifier "" was successful against account "my_account".
Shell is not supported.
然而,当我 git clone ssh://[user]@[host]:22/[repo]
时,它失败了!
However, when I git clone ssh://[user]@[host]:22/[repo]
, it fails!
Your Git command did not succeed.
Details:
Public key authentication failed.
出乎意料的是,如果我使用id_github
的公钥,则克隆成功.怎么回事?
In an unexpected turn of events, if I use id_github
's public key, the clone succeeds. What's going on?
推荐答案
需要强制客户端使用特定的私钥,否则使用默认的.
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)]
一种方法是您可以在配置文件中对其进行配置.(我的 windows 步骤)
One way is that you can configure it in the config file. (My steps for windows)
- 如果 .ssh 文件夹中没有配置文件,请运行
touch .ssh/config
- 打开配置文件
代码:
Host xx.visualstudio.com
IdentityFile /c/Users/xx/.ssh/id_vsts
- 打开新的命令行并运行
Git clone
命令
另一种方法是,您可以运行 ssh -i/path/to/id_rsa user@server.nixcraft.com
命令.
Another way is that, you can run ssh -i /path/to/id_rsa user@server.nixcraft.com
command.
更多信息,可以参考这篇文章:强制 SSH 客户端使用给定的私钥(身份文件)
More information, you can refer to this article: Force SSH Client To Use Given Private Key (identity file)
这篇关于`ssh -T` 到 VSTS(Azure Devops) 认证成功,但 `git clone` 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!