同一台主机两个github账号切换使用

同一主机两个github账号切换使用

可能某些原因,我们需要在公司与个人之间切换相关的开发者账号。如同一台主机两个github账号

此为windows环境

操作步骤如下

首先,创建2组 公私钥

默认用户目录 ~/.ssh

bash 复制代码
$ ssh-keygen -t ed25519 -C "[email protected]"
Enter file in which to save the key (~/.ssh/id_ed25519):
# 回车, 默认生成 id_ed25519 和 id_ed25519.pub

$ ssh-keygen -t ed25519 -C "[email protected]"
Enter file in which to save the key (~/.ssh/id_ed25519):
# 录入 id_ed25519_sec, 生成 id_ed25519_sec 和 id_ed25519_sec.pub

其次,生成一个新文件 ~\.ssh\config

假设两个github账号分别为

comment username email
github-one oneAcc [email protected]
github-sec testeru [email protected]
bash 复制代码
# Default account (first account)
Host github-one
    HostName github.com
    PreferredAuthentications publickey
    User git
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

# Second account
Host github-sec
    HostName github.com
    PreferredAuthentications publickey
    User git
    IdentityFile ~/.ssh/id_ed25519_sec
    IdentitiesOnly yes

再次,将生成的公钥分别放入不同的github账号中

github > settings -> keys -> Access -> SSH and GPG keys -> New SSH key

最后测试

假设 second account 账号实际为 testeru, 且有一个repository 为abc

复制代码
$ git clone git@github-sec:testeru/abc.git

备注

代码修改提交(可能会失败),如失败,设置当前目录下的用户为

bash 复制代码
$ git config user.name testeru
$ git config user.email [email protected]
相关推荐
Yvonne爱编码4 小时前
CSS- 4.1 浮动(Float)
前端·css·html·github·html5·hbuilder
冷yan~6 小时前
GitHub文档加载器设计与实现
java·人工智能·spring·ai·github·ai编程
qianmoQ2 天前
GitHub 趋势日报 (2025年05月14日)
github
Yvonne爱编码2 天前
CSS- 2.1 实战之图文混排、表格、表单
前端·css·html·github·状态模式·html5·hbuilder
qianmoQ2 天前
GitHub 趋势日报 (2025年05月11日)
github
Yvonne爱编码2 天前
HTML-3.3 表格布局(学校官网简易布局实例)
前端·html·github·html5·hbuilder
范纹杉想快点毕业2 天前
以项目的方式学QT开发(一)——超详细讲解(120000多字详细讲解,涵盖qt大量知识)逐步更新!
c语言·数据结构·c++·git·qt·链表·github
tonngw2 天前
【Mac 从 0 到 1 保姆级配置教程 12】- 安装配置万能的编辑器 VSCode 以及常用插件
git·vscode·后端·macos·开源·编辑器·github
八股文领域大手子3 天前
HTTP/1.1 host虚拟主机详解
github
HORSE RUNNING WILD3 天前
解决 PicGo 上传 GitHub图床及Marp中Github图片编译常见难题指南
css·python·github