Two different bitbucket accounts, macOS High Sierra - Permission denied (publickey). Edited

Hey!

I've a private bitbucket account and one of my company.
SourceTree has automatically configured my ssh config file, where each entry (for each account) starts with "Host <username>-Bitbucket".
Since macOS Sierra, it isn't possible anymore to communicate with my bitbucket repos.
If I change the entry to "Host bitbucket.org" it works for the first account, depends on which entry is listed first. For both entries, following settings are configured:

HostName bitbucket.org
User <username>
PreferredAuthentications publickey
IdentityFile /Users/<user>/.ssh/<username>-Bitbucket
UseKeychain yes
AddKeysToAgent yes

Both passphrases are stored correctly in the keychain. I'm using SourceTree by the way, but it's the same in the terminal.

I would be so grateful to you, if you can help me - it's so annoying, the only workaround which i know, call "ssh-add -A" after booting.

Thanks guys!

1 answer

0 vote

Hi Andreas, if this issue is also happening to you in the terminal, then it's not caused by Sourcetree :)

To add both your Bitbucket accounts credentials separately, you can follow the instructions in this post Different SSH keys for different accounts on same Git hosting.

You can also find more info in our official documentation at Set up additional SSH keys.

You can also test the BitBucket server to see which account you are logging in with, to do that run:

ssh -v git@bitbucket.org

And lastly if you need to cheack that the Keychain has the right kays, you can see all of them by running:

ssh-add -l

Let us know if this helps!

Best regards,

Ana

Hey Ana, thank you very much for your help :)

The ssh -v git@bitbucket.org command really helps a lot to figure out such problems. (I've also tried <user>@bitbucket.org)

I found out, that the ssh-agent always wants to use my default key (id_rsa) because of this output:
debug1: /Users/andreas/.ssh/config line 34: Applying options for *
This matches the line "Host *" of my ssh config.

I think anyway, SourceTree has some effect to this, here is my generated entry in the ssh config:

# --- SourceTree Generated ---
Host <user>-Bitbucket
    HostName bitbucket.org
    User <user>
    PreferredAuthentications publickey
    IdentityFile /Users/andreas/.ssh/<user>-Bitbucket
    UseKeychain yes
    AddKeysToAgent yes
# ----------------------------

So when does ssh choose exactly this key, located at the "IdentityFile" path.
The command mentioned above uses the key referenced "Host *", not the key of "Host <user>-Bitbucket".

In your link "Different SSH keys ..." I've seen the ssh-add command to add the new key - this works, but I don't want to do this after every restart. :/
So the problem is in the line "Host <user>-Bitbucket" I think, because the output should then be like "Applying options for <user>-Bitbucket".

Btw, my colleague has the same problem since a few days.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

794 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you