I had the same problem, except the error message I got sounded:
Permission denied (publickey,password)
Instead of trying and erring with lots of different answers, I went after the root cause of the problem. I found out that the ssh configuration file, which is ~/.ssh/config
, plays a role in this matter. In my case it contained two records:
# --- ssh to OUNL ---
Host *
HostName 145.20.188.96
User sjo
PreferredAuthentications publickey
IdentityFile /Users/sjo00577/.ssh/id_ou_rsa
UseKeychain yes
AddKeysToAgent yes
# --- Sourcetree Generated ---
Host *
HostName github.com
User stefjoosten
PreferredAuthentications publickey
IdentityFile /Users/sjo00577/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes
# ----------------------------
When I swapped both records, ssh to github worked again, but ssh to 145.20.188.96 did not work anymore. This prompted me to read a manual for the ssh config file. Apparently, the first occurrence of host *
is used for every host, so the github host is shadowed entirely. The following solution solved the problem: Just let the first record refer only to the designated host instead of all hosts:
# --- ssh naar OUNL ---
Host 145.20.188.96
User sjo
PreferredAuthentications publickey
IdentityFile /Users/sjo00577/.ssh/id_ou_rsa
UseKeychain yes
AddKeysToAgent yes
# --- Sourcetree Generated ---
Host *
HostName github.com
User stefjoosten
PreferredAuthentications publickey
IdentityFile /Users/sjo00577/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes
# ----------------------------
This works fine and it solved the problem. Even better is to confine github to the correct host too. So I guess that you want to look for the problem in ~/.ssh/config
. I reckon that this solution will also work in situations other than Sourcetree on MacBook only.