我梦

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

git拉取多个仓库代码配置多个密钥

当你需要使用多个仓库地址并且使用不同的ssh密钥时就会遇到配置问题。

先看配置文件 ~/.ssh/config

Host github.com-just-beginer
  HostName github.com
  User yicon
  IdentityFile ~/.ssh/github_rsa
Host gitee.com-justshuang
  HostName gitee.com
  User xushuang
  IdentityFile ~/.ssh/ubuntu2_id_rsa

配置文件如上面所示

主要问题的就是指定 Host,用来区分不同的账号

git@github.com:just-beginer/translate-api.git

git@github.com:xushuangxushuang/go-hello.git

这是两个不同的github账号下的ssh仓库地址

相应的配置应该是下面两种情况

Host github.com-just-beginer

  HostName github.com

  User [用户名]

  IdentityFile [私钥地址]

 

Host github.com-xushuangxushuang

  HostName github.com

  User [用户名]

  IdentityFile [私钥地址]

可以使用ssh -T 命令进行测试

ssh -T git@github.com-just-beginer

Hi just-beginer! You've successfully authenticated, but GitHub does not provide shell access.

区别就是Host后面用中划线(-) 分隔开仓库地址域名后面的用户名

git clone时的地址也需要换成相应的Host

上面的两个地址克隆时:

git clone git@github.com-just-beginer:just-beginer/translate-api.git

git clone git@github.com-xushuangxushuang:xushuangxushuang/go-hello.git

这里类linux上的配置,windows上的配置也是一样的,可以找到windows下用户

名目录下隐藏的ssh目录自行配置

参考文章:https://www.freecodecamp.org/chinese/news/manage-multiple-github-accounts-the-ssh-way

  

  

 

posted on   我梦  阅读(107)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示