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

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

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

此为windows环境

操作步骤如下

首先,创建2组 公私钥

默认用户目录 ~/.ssh

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

$ ssh-keygen -t ed25519 -C "your_email_1@example.com"
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 oneAcc@aa.cc
github-sec testeru testeru@xx.cc
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 testeru@xx.cc
相关推荐
杨凯凡4 小时前
IT日报|2026-11-20:欧盟 AI 网络攻击、Valkey 9.2、GitHub 企业迁移
人工智能·github
TunerT_TQ5 小时前
Terraform OCI Provider 2026:工具链的骨架清晰可见,CRUD 的肌肉必须由你亲自验证
github
prince_zxill5 小时前
把 17 个散文件装进一个文件夹:拆解 claude-plugins-official 的插件打包术(47,413 Star 实测)
python·github·agent·mcp·claude code
wflynn6 小时前
GitHub 日榜趋势速报 | 2026-11-20
开源·github
TunerT_TQ8 小时前
【开源评测】google-labs-code/stitch-skills:从设计交接到可检查的组件产物
github
一条Go9 小时前
探测规则:为什么它是告警规则的一种,而不是独立的任务体系
后端·架构·github
一条Go9 小时前
开源新生代雷达 · 第 17 期
github
怕浪猫10 小时前
2026 GitHub 最火的 10 个视频制作与剪辑开源项目:AI 出片、代码生视频、无损剪辑怎么选(附实测截图)
github
dong_junshuai1 天前
每天一个开源项目#162 NGINX:流式响应背后的缓冲、背压与重试
github
测试员周周1 天前
【agent评测】:真实系统演示工具调用长什么样,用例怎么设计,怎么测
前端·后端·github