同一台主机两个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
相关推荐
逛逛GitHub11 小时前
飞书多维表“独立”了!功能强大的超出想象。
人工智能·github·产品
努力的小雨13 小时前
混元开源之力:spring-ai-hunyuan 项目功能升级与实战体验
后端·github
NocoBase14 小时前
GitHub 上 Star 数量前 10 的开源项目管理工具
开源·github·资讯
绝无仅有14 小时前
面试实战总结:数据结构与算法面试常见问题解析
后端·面试·github
绝无仅有14 小时前
Docker 面试常见问题及解答
后端·面试·github
逛逛GitHub1 天前
斩获 2 万多 Star!国外老哥把全网 n8n 工作流都开源了
github·工作流引擎
杨杨杨大侠2 天前
Atlas Mapper 案例 01:初级开发者 - 电商订单系统开发
java·开源·github
绝无仅有2 天前
后端 Go 经典面试常见问题解析与总结
后端·面试·github
绝无仅有2 天前
后端工程师面试常见问题与回答解析总结
后端·面试·github
逛逛GitHub2 天前
发现一个 AI 大模型服务质量榜单。
github