同一台主机两个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
相关推荐
钱塘江渔夫41 分钟前
一键式解决Windows访问github.com不了问题
windows·github
Resistance丶未来2 小时前
Coding-Interview-University 学习路径实战评测
人工智能·gpt·学习·github·claude·gemini·kimi
James_WangA15 小时前
我给 AOI 设备装了一个 Agent,然后发现工具注册才是最难写的
架构·github
James_WangA15 小时前
产线上跑 Agent:LLM 挂了不是 500 错误,是停线
架构·github
Hommy8819 小时前
【开源剪映小助手】字幕接口
开源·github·aigc·剪映小助手·视频剪辑自动化
一袋米扛几楼9821 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
尘埃落定wf1 天前
# GitHub CLI:告别繁琐的 Git 命令,让开发更高效
git·github
zh_xuan1 天前
上传api调试工具到github
github
AIMath~1 天前
彻底删除 GitHub 仓库中特定文件夹的完整指南
github
DogDaoDao1 天前
【GitHub】OpenClaw:开源个人AI助手的新标杆
人工智能·深度学习·开源·大模型·github·ai编程·opeclaw