简体   繁体   English

无法在 Mac M1 Monterrey 上使用不同的 ssh 密钥管理多个 github 存储库

[英]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.我正在尝试在 Mac M1 Monterrey 上使用不同的 ssh 密钥管理多个 github 存储库。 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 = user1@gmail.com

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

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

and my SSH config和我的 SSH 配置

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.用户 1 是我的主要工作人员。

I have tried to authenticate using user-2 's credentials which seem to work.我尝试使用似乎有效的user-2凭据进行身份验证。

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:但是,当我尝试使用project2中的配置提取我是协作者的私人仓库时,我收到以下错误:

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.我将不胜感激任何指导。

Oh... i just saw what the problem is.The url for the repo is not using ssh but https:哦...我刚刚看到问题所在。回购的 url 没有使用 ssh 而是 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: 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是这样的:

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

My guess.我猜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM