简体   繁体   中英

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. 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. The repo that works depends on which SSH key is sorted first in the Pageant key list.

By "fail", I mean that the following error is returnded from the Git command:

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. 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. In other words, when a key is not attached to any Bitbucket account, then Bitbucket doesn't seem to have an issue with it.

Has anyone gotten Pageant to work with keys loaded simultaneously for multiple Bitbucket repos?

I found an answer in this blog that worked for me: 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)
  3. Go to Connection > SSH > Auth and load your second private key under Private Key File for Authentication
  4. Go to Session , and type a name with no spaces in Saved Sessions , and click 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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