I'm using SourceTree 2.4.1 on Mac with my Bitbucket account. I authenticate with Google and use SSH.
Every time I have restarted my system, I'm getting an error in SourceTree (see below).
I then remove my account in SourceTree and set everything up again (including SSH) to get things working again which is quite frustrating if you need to do it at least once a week.
Can anyone help me out?
-------------------
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree fetch --prune origin
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Permission denied (publickey).
fatal: Could not read from remote repository.
If your config file uses UseKeychain yes and AddKeysToAgent yes for Bitbucket/GitHub and you're finding ssh-add -K only works until you reboot your Mac, make sure the Host is set to github.com and bitbucket.org. This is actually the alias for the host record. SourceTree was causing SSH to use the default id_rsa key because it wasn't using the alias name when firing the ssh command.
This fixed the recurring issue for me that forced the awful GitHub Desktop upon me. Thank goodness.
Thank you for this answer.
I had the same issue and in fact the ssh config file, generated by Sourcetree (v2.6.3) was including this info :
# --- Sourcetree Generated ---
Host BunCBG-Bitbucket
HostName bitbucket.org
User bunCBG
PreferredAuthentications publickey
IdentityFile /Users/christophe/.ssh/bunCBG-Bitbucket
UseKeychain yes
AddKeysToAgent yes
# ----------------------------
You'll notice that the host is in fact the name of my key. I just changed it to bitbucket.org and it seems the problem is gone. My SSH key is now correctly detected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works until you have only one Bitbucket account.
In my case, I've two different accounts - a private and one for ma company.
Of course the host is the same both times (bitbucket.org). Means it will always use the first entry and uses the wrong key, if I want to authenticate with the key of the second entry.
I thought the user field has effect for the request, but if not even the host matches, the user doesn't matter.
I can set the host to user@bitbucket.org, then I've to change the remote address of the repository, which works quite well. The problem then is, that submodules always use git@bitbucket.org, otherwise my colleagues have the wrong username inside their .gitmodules file.
Is there any solution for different Bitbucket accounts? Besides, why SourceTree writes "Host User-Bitbucket" into the ssh config file, if it doesn't work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Christophe!!!!
I was going crazy!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Christophe!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Christophe SAUVEUR: "You'll notice that the host is in fact the name of my key. I just changed it to bitbucket.org and it seems the problem is gone. My SSH key is now correctly detected."
Thanks! It works for me
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Worked perfectly for me on MacOS Mojave 10.14.3!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks mate. It fixed my issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! Fixed my issue as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! I get frustrated every time my machine is rebooted and I have to setup my git credentials again and again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've recently discovered something really useful with this issue.
The core.sshCommand config for git. It allows to select the specific SSH key per repository.
More information here: https://superuser.com/a/912281
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using SourceTree. Where would I add the code they mention there?
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you are using macOS, you can do Actions > Open in terminal
Howeever, I suggest adding the --local attribute to the command-line if you want to specify core.sshCommand only for the current repository.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is not working for me. When I reboot my machine, I have to add my key to the agent.
I have followed the answer given by @Christophe SAUVEUR on January 13, 2018 and entered the required info in the ssh config file. Yet after reboot, the key is lost and have to re-add it with `ssh-add -K ...`
Using macOS Mojave 10.14.2. Any ideas?
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're using two accounts of bitbucket I guess? Otherwise the answer you mentioned is working. Maybe delete all the passphrases from your keychain app and try to add the keys per hand afterwards (see commands below).
My workaround is to comment out all the sections where the "Host" is exactly the same which I want to use now, except the latter one.
Then delete and re-add the keys (ssh-add -D and ssh-add -A)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply, but it doesn't work. I only have a single account.
Before, my config file was:
Host *
UseKeychain yes
Then I tried to add:
Host *
UseKeychain yes
AddKeysToAgent yes
None of these worked. I still had to use `ssh-add -K ...` each time I rebooted. I Googled this issue a few times and read various answers on stackoverflow. They all recommended the above solutions.
Then I found this thread recently and changed my config file to this (as per above recommendation) - where the <...> entries represent my actual user name:
Host <user>-Bitbucket
HostName bitbucket.org
User <user>
PreferredAuthentications publickey
IdentityFile /Users/<USERNAME>/.ssh/<my-ssh-keyfile-name>
UseKeychain yes
AddKeysToAgent yes
I have already did `ssh-add -D` and re-added the keys before with `ssh-add -K` and also tried `ssh-add -A`. But after restart, I still have to add them again because they are not remembered.
Totally frustrating.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Look at this. I think it should help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Older question but still an issue I just encountered. This answer is working for me for multiple accounts on mac osx (sierra):
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maël,
If you're on 10.12, I'd recommend entering a few values into your SSH config, which should autoload your keyfile: https://developer.apple.com/library/content/technotes/tn2449/_index.html
Cheers,
Jesse
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maël,
do you have any solution for my problem I reported above? I've commented to Ben Stones answer.
Would be nice, because I've the problem since a year and it's really annoying - not only my problem, also to change every time the Host field of the ssh config.
BG
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
Since I have only 1 account Ben's solution worked for me.
I don't know how to fix this for multiple accounts, sorry!
- Maël
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have just tried re-connecting with Google (instead of removing the account) and it worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.