简体   繁体   中英

Can't SSH into my Bitbucket repository - conq: repository access denied

I have followed a million guides regarding this and I cannot get it to work. Earlier, I successfully pushed via SSH to my private Bitbucket git repository, now suddenly it wont work.

I have recreated the keys with a new passphrase, added it to my Bitbucket settings and it wont work.

Okay, here are the steps I took:

  1. Deleted old key pair (project1 and project1.pub)
  2. Recreated it with this command ssh-keygen -f ~/.ssh/project1 -C "project1"
  3. Created a config in ~/.ssh file for my two Bitbucket accounts, with the following contents:

Host project1 HostName bitbucket.org IdentityFile ~/.ssh/project1 Host project2 HostName bitbucket.org IdentityFile ~/.ssh/project2

  1. Grabbed the contents of project1.pub and created a new SSH key entry in my Bitbucket account.
  2. Added ssh-agent in my ~/.zshrc plugin list like this: plugins=(git ssh-agent) and restarted Terminal
  3. Did ssh-add -l and saw only project2 was loaded
  4. Did ssh-add ~/.ssh/project1 , entered my passphrase and success, like this:

2048 SHA256:THESHA256 /Users/myuser/.ssh/project2 (RSA) 2048 SHA256:THESHA256 /Users/myuser/.ssh/project1 (RSA)

  1. Restarted Terminal and did ssh-add -l and it listed both entries
  2. Went to my project and did git push and it told me I had no access.

When I do ssh -T git@bitbucket.com , it tells me I'm logged in with the username of project2 .

logged in as project2_user.

My system is OS X 10.11.5

I could never fix multiple identities on my computer and always used HTTPS, but I need to make everything more secure with SSH, which also allows my account to have two-factor authentication. Therefore using SSH is a must now and I don't know what to do.

PS: I did the creating steps for the identity for project2 too, but I'm fairly certain that it doesn't work either.


Guide I followed:

https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html


EDIT

project2 has no passphrase, while project1 does! Just thought maybe this is relevant.

EDIT 2

I did ssh-add -D to remove all loaded keys, then added the key for project1 , entered passphrase and pushed. It worked. But now my other identity is not working because its key is not loaded.

Why aren't my multiple identities working?

If different repositories on the same remote host require usage of different SSH identities then you must use SSH aliases.

Check that remote.origin.url has the following (or equivalent) values in your local repositories:

  • project1 : git@bitbucket.org:accountX/project1.git
  • project2 : git@bitbucket.org:accountY/project2.git

accountX may be either your account associated with your 1st identity on Bitbucket (ie project1_user ), or another account that has granted access to project1_user to their repository project1 . The same goes for project2 .

Now, when git has to connect to the remote repository from your local repository, it will first have to connect to the remote server, and the latter for your both projects is set to bitbucket.org . Then, how does git know which SSH identity to use? It picks some identity associated with bitbucket.org .

Update your remote.origin.url settings as follows:

  • project1 : git@project1:accountX/project1.git
  • project2 : git@project2:accountY/project2.git

Then, when git is told to connect to git@project1 , it resolves project1 to the corresponding entry in ~/.ssh/config and uses the identity specified therein. Similarly for project2 .

Basing on my experience you can save yourself lot of time and efforts using HTTPS in this circumstance.

I'd not success with multiple SSH identities few months ago.

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