1

I've two Bitbucket accounts. One for office and the other is personal. Now I've also created two SSH keys for these accounts and added the keys but seems now I can't access to my personal account.

When I try git push -u origin develop, I get this error:

repository access denied.
fatal: Could not read from remote repository.

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

This is my .ssh/config file:

 1 Host bitbucket.org
 2        User git
 3        Hostname bitbucket.org
 4        IdentityFile ~/.ssh/id_rsa_bitbucket
 5        TCPKeepAlive yes
 6        IdentitiesOnly yes
 7
 8 Host bitbucket.org
 9        User git
 10        Hostname bitbucket.org
 11        IdentityFile ~/.ssh/id_rsa
 12        TCPKeepAlive yes
 13        IdentitiesOnly yes

First one is for my office and 2nd one is for my personal account. Any idea how can I solve this problem?

Melebius
  • 6,183
  • 4
  • 39
  • 52
Ariful Haque
  • 3,662
  • 5
  • 37
  • 59

3 Answers3

0

You have to name them differently:

Host bitbucket1
    User git
    Hostname bitbucket.org
    IdentityFile ~/.ssh/id_rsa_bitbucket
    TCPKeepAlive yes
    IdentitiesOnly yes

Host bitbucket2
    User git
    Hostname bitbucket.org
    IdentityFile ~/.ssh/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes

And in your git repositories use bitbucket1 or bitbucket2 instead of bitbucket.org.

phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    Unfortunately, this did not work as well :( But I made it work with a different approach. I'll explain it in another answer. – Ariful Haque Jul 13 '17 at 13:49
  • >>>And in your git repositories use bitbucket1 or bitbucket2 instead of bitbucket.org Where and how ??? in settings of repository, there is no any adjusting the name of host – Nurbek Nurjanov May 16 '20 at 05:40
  • @NurbekNurjanov In `git clone` or `git remote set-url`. – phd May 16 '20 at 05:59
0

Bitbucket permits usernames other than "git" or "hg" for SSH access to repos. You could do something like git remote set-url origin myawesomeusername@bitbucket.org:owner/repo.git on your work-related repos (assuming "myawesomeusername" is your username and "owner/repo.git" is the path to the repo in question), or you could edit the .git/config file in each repo to change git@bitbucket.org in the URL to myawesomeusername@bitbucket.org.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
-1

Most probably there was some conflict with my two ssh keys and my private account could not get any permission from this machine to my Bitbucket.

So suddenly I thought to assign my office ID to my personal repo from

Settings > User and Group Access > User

and give that ID Admin permission and it worked perfectly.

Maybe this is not the elegant way and not the actual solution of the problem but it works perfectly at this moment.

Ariful Haque
  • 3,662
  • 5
  • 37
  • 59