0

I have a problem with my Bitbucket multiple accounts.

This is my current situation:

  • MacOS Catalina 10.15.5

  • My ~/.ssh folder has this:

-rw-------+   1 myuser  mygroup   1679 12 oct  2016 id_rsa
-rw-r--r--@   1 myuser  mygroup    411 12 oct  2016 id_rsa.pub
-rw-------+   1 myuser  mygroup   1823 25 feb 13:50 mycompany
-rw-r--r--@   1 myuser  mygroup    394 25 feb 13:50 mycompany.pub
  • I have a Bitbucket company account whose SSH key is the same as mycompany.pub

  • I have a Bitbucket personal account whose SSH Key is the same as id_rsa.pub

Whenever I do anything related with my Bitbucket personal account (git clone, push...) everything works fine.

On the other hand, to do things with my Bitbucket company account I have to add my username to the commands, for example:

git clone https://mycompany@bitbucket.org/blablabla

If I don't add my username I get permission errors. This is a big problem using scripts that I cannot modify (for example with "pod lib lint" and things that access bitbucket private repositories of my company).

What I've tried so far:

  • Checking if my ssh-agent is running:
$ eval `ssh-agent -s`
Agent pid 5788
  • Checking my ssh-agent shows this:
$ ssh-agent sh -c 'ssh-add; ssh-add -l'
Identity added: /path/to/my/user/.ssh/id_rsa (/path/to/my/user/.ssh/id_rsa)
2048 SHA256:... /path/to/my/user/.ssh/id_rsa (RSA)
  • Since I see my ssh-agent doesn't include my company key I add it:
$ ssh-add ~/.ssh/mycompany
Identity added: /path/to/my/user/.ssh/mycompany (mycompany)
  • But if I check my ssh-agent again, the key has not been included:
$ ssh-agent sh -c 'ssh-add; ssh-add -l'
Identity added: /path/to/my/user/.ssh/id_rsa (/path/to/my/user/.ssh/id_rsa)
2048 SHA256:... /path/to/my/user/.ssh/id_rsa (RSA)

I've tried too changing my ~/.ssh config file from this:

Host *
  UseKeychain yes

To this:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host mycompanybitbucket
  Hostname bitbucket.org
  User mycompany
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/mycompany

Restarted the shell and trying all again, with the same results: I have no permissions to access my company bitbucket repos.

What am I missing?

EDIT:

I've tried another thing that make things more confusing.

If I overwrite id_rsa and id_rsa.pub with mycompany and mycompany.pub and run this:

ssh-agent sh -c 'ssh-add; ssh-add -l'

The output is this:

Identity added: /path/to/my/user/.ssh/id_rsa (mycompany)
2048 SHA256:... mycompany (RSA)

This made me thing that the certificate was this time the correct one and everything should work well. But not, after this, all git commands keep returning permission error.

Wonton
  • 1,033
  • 16
  • 33

1 Answers1

0

Well, I finally figured it out. My problem was with all access to https://bitbucket.org, they needed to include the username but in some places I wasn't able to edit these URLs.

So I was studying how to add a default username to these URLs and it worked. Just running these 2 commands fixed my problem:

$ git config --global credential.helper cache
$ git config --global credential.https://bitbucket.org.username mycompany
Wonton
  • 1,033
  • 16
  • 33