简体   繁体   English

从 Bitbucket Git Repos 拉取时,Pageant 中的多个 SSH 键会导致失败

[英]Multiple SSH keys in Pageant cause failures when pulling from Bitbucket Git Repos

I'm having a problem very similar to the one described here .我遇到的问题与此处描述的问题非常相似。 However, the difference is that I'm trying to use Pageant as my agent instead of OpenSSH.然而,不同之处在于我正在尝试使用 Pageant 作为我的代理而不是 OpenSSH。 I've found that when I have the SSH keys for two different Bitbucket accounts loaded in Pageant that one of the two repos will always run Git commands and the other will fail.我发现当我在 Pageant 中加载了两个不同的 Bitbucket 帐户的 SSH 密钥时,两个存储库之一将始终运行 Git 命令,而另一个将失败。 The repo that works depends on which SSH key is sorted first in the Pageant key list.工作的 repo 取决于哪个 SSH 键在 Pageant 键列表中排在第一位。

By "fail", I mean that the following error is returnded from the Git command: “失败”是指从 Git 命令返回以下错误:

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks fetch origin
Forbidden
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Completed with errors, see above.

I don't know if this is a PuTTY/Pageant, a SourceTree, or a Bitbucket problem.我不知道这是 PuTTY/Pageant、SourceTree 还是 Bitbucket 问题。 I suspect it is a Bitbucket issue since I found that if I remove Key A from Bitbucket Account A and then try to fetch on Repository B, then the command will succeed, even when Keys A and B are both loaded in Pageant.我怀疑这是一个 Bitbucket 问题,因为我发现如果我从 Bitbucket 帐户 A 中删除密钥 A,然后尝试在存储库 B 上获取,那么即使密钥 A 和 B 都加载到 Pageant 中,命令也会成功。 In other words, when a key is not attached to any Bitbucket account, then Bitbucket doesn't seem to have an issue with it.换句话说,当密钥未附加到任何 Bitbucket 帐户时,Bitbucket 似乎没有问题。

Has anyone gotten Pageant to work with keys loaded simultaneously for multiple Bitbucket repos?有没有人让 Pageant 使用同时为多个 Bitbucket 回购加载的密钥?

I found an answer in this blog that worked for me: craigtp.co.uk我在这个对我有用的博客中找到了答案: craigtp.co.uk

For your first account and key, just set it up normally.对于您的第一个帐户和密钥,只需正常设置即可。

For the second account,对于第二个帐户,

  1. Start PuTTY启动腻子
  2. In Host Name , type in the real address (eg github.com)Host Name中,输入真实地址(例如 github.com)
  3. Go to Connection > SSH > Auth and load your second private key under Private Key File for Authentication Go 到Connection > SSH > Auth并在Private Key File 下加载您的第二个私钥以进行身份验证
  4. Go to Session , and type a name with no spaces in Saved Sessions , and click Save. Go 到Session ,然后在Saved Sessions中键入一个没有空格的名称,然后单击 Save。 That will be your alias.那将是你的别名。

For instance, if you named your alias github-second , then when you clone your repository for your second account, use the alias.例如,如果您将别名命名为github-second ,那么当您为第二个帐户克隆存储库时,请使用别名。 Eg例如

git clone git@github-second:blah/blahblah.git

For what you are saying, it seems you have already cloned the repository at some point in time.对于您所说的,您似乎已经在某个时间点克隆了存储库。 In which case, simply update the remote.在这种情况下,只需更新遥控器即可。

Check your current remote.检查您当前的遥控器。 It should look like this,它应该看起来像这样,

git remote -v
origin  git@github.com:blah/blahblah.git 

Then, update the remote with this command:然后,使用以下命令更新遥控器:

git remote set-url origin git@github-second:blah/blahblah.git

That should work.那应该工作。

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

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