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


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" it works for the first account, depends on which entry is listed first. For both entries, following settings are configured:

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 votes

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

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,


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

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

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
    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
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,095 views 4 2
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