1

I've got some SPM dependencies which are private Bitbucket repositories to which I have access to. However, when SPM is resolving dependencies, I'm getting an error:

Error while fetching remote repository <my_repository.git>: An unknown error occurred. The requested repository either does not exist or you do not have access. If you believe this repository exists and you have access, make sure you're authenticated. (-20)

The problem boils down to the fact that I have two different Bitbucket accounts with different SSH keys, so apparently SSH protocols tries keys in order, and once finds one that works, it uses that one - sadly, it's not a valid one to authenticate this particular repository.

I had the same error trying to clone the repositories in Source Tree, but I managed to resolve it by having Source Tree create new SSH key (funny enough, there's no way to just chose a different existing key in Source Tree, just create a brand new one)

Is there a way to define which SSH key Xcode should use? Or some kind of global config/setting to tell SSH which key should be used as default?

Edit
Editing ~/.ssh/config and defining IdentityFile ~/.ssh/key_i_want_to_use seems to have done the trick, but a global setting doesn't seem optimal. Is there a way to select the key just in Xcode? Ideally, select it per project?

mag_zbc
  • 6,801
  • 14
  • 40
  • 62
  • 1
    You can try [`git config --local core.sshCommand "ssh -i ~/.ssh/project_key"`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresshCommand) per project but the most accepted way to solve this is a [global multi-project ssh config](https://stackoverflow.com/q/3860112/7976758). See https://stackoverflow.com/search?q=%5Bgit%5D+multiple+ssh+accounts – phd Dec 01 '22 at 11:56

0 Answers0