0xsegfault
0xsegfault

Reputation: 3161

Unable to manage multiple github repositories with different ssh keys on Mac M1 Monterrey

I am trying to manage multiple github repositories with different ssh keys on Mac M1 Monterrey. I have followed the steps mentioned in the below link..

Here is what my project structure looks like

Home
.gitconfig
|_project1
    |_ .gitconfig1  
|_project2
    |_ .gitconfig2
# .gitconfig in Home
[includeIf "gitdir:~/project1/"] 
path = ~/project1/.gitconfig1
 
[includeIf "gitdir:~/project2/"]
path = ~/project2/.gitconfig2 

[core]
excludesfile = ~/.gitignore 
# .gitconfig2 in project1
[user]
    name = User 1
    email = [email protected]

[github]
user = "user-1"
 
[core]
sshCommand = "ssh -i ~/.ssh/user-1"
# .gitconfig2 in project2
[user]
    name = User 2
    email = [email protected]

[github]
user = "user-2"
 
[core]
sshCommand = "ssh -i ~/.ssh/user-2"

and my SSH config

Host github.com-user-1
   HostName github.com
   User git
   IdentityFile ~/.ssh/user-1
   IdentitiesOnly yes
   AddKeysToAgent yes
   UseKeychain yes
   PasswordAuthentication no

Host github.com-user-2
   HostName github.com
   User git
   IdentityFile ~/.ssh/user-2
   IdentitiesOnly yes 

User 1 was my primary and works.

I have tried to authenticate using user-2's credentials which seem to work.

ssh -T github.com-user-2
Hi user-2! You've successfully authenticated, but GitHub does not provide shell access.

However , when i try to pull a private repo where I am a collaborator using the config in project2 , I get the following error:

Cloning into 'foo2'...
remote: Repository not found.
fatal: repository 'https://github.com/some-project/some-repository.git/' not found

I would appreciate any guidance with this.

Upvotes: 2

Views: 57

Answers (1)

eftshift0
eftshift0

Reputation: 30166

Oh... i just saw what the problem is.The url for the repo is not using ssh but https:

https://github.com/some-project/some-repository.git/

Change the URL to use ssh and it should work.... and now that I think about it, it's not just ssh, it has to be adapted to have the Host as you have it in your ssh config... so it should be something like:

github.com-user-2:some-project/some-repository.git

My guess.

Upvotes: 2

Related Questions