我试图找出如何使用VSTS多个SSH密钥。我有两个不同的VSTS帐户和一个与每个帐户相关联的SSH密钥。只要我一次只向SSH-Agent添加一个密钥,我就可以很好地连接到该帐户的存储库。然而,一旦我将两个密钥添加到代理,我将始终为第二个帐户登录失败,因为它将使用第一个帐户的密钥。我认为这可能是与Windows上的SSH相关的行为,但我在OSX上也有相同的行为。
>git clone ssh://[email protected]:22/DefaultCollection/_ssh/your-repo
Cloning into 'your-repo'...
remote:
remote: Your Git command did not succeed.
remote: Details:
remote: Public key authentication failed.
remote:
fatal: Could not read from remote repository.
我的.ssh / config的相关部分目前如下所示。我已经弄乱了主机值,但我尝试过的任何东西都没有什么区别。
Host [email protected]
Hostname vs-ssh.visualstudio.com
User account1
IdentityFile ~/.ssh/id_account1_vsts
AddKeysToAgent yes
UpdateHostKeys yes
Host [email protected]
Hostname vs-ssh.visualstudio.com
User account2
IdentityFile ~/.ssh/id_account2_vsts
AddKeysToAgent yes
UpdateHostKeys yes
您不能将此值用作Host,请将其替换为:
Host hostaccount1
Hostname vs-ssh.visualstudio.com
User account1
IdentityFile ~/.ssh/id_account1_vsts
AddKeysToAgent yes
UpdateHostKeys yes
Host hostaccount2
Hostname vs-ssh.visualstudio.com
User account2
IdentityFile ~/.ssh/id_account2_vsts
AddKeysToAgent yes
UpdateHostKeys yes
然后,您可以像这样克隆存储库
git clone ssh://hostaccount2:22/_ssh/{repo}
git clone ssh://hostaccount1:22/_ssh/{repo}
(将[email protected]
替换为hostaccount1
,与hostaccount2
相同)