同一台主机两个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
相关推荐
一点一木7 小时前
🚀 2026 年 4 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
宝桥南山9 小时前
AI - 在命令行中尝试一下ACP(Agent Client Protocol)通信
microsoft·微软·github·aigc·copilot
拾贰_C12 小时前
【Github | GitHub Copilot | 学生认证】 GitHub Copilot学生如何认证
github
旅之灵夫13 小时前
【GitHub项目推荐--OpenArm:开源7自由度仿人机械臂平台】
github
一乐小哥14 小时前
坚持迭代一个 Chrome 插件半年后,我的同事问我:"这不是 Chrome 自带的功能吗?"
chrome·github·ai编程
Smilezyl14 小时前
一个独立开发者,靠一份 markdown 驱动 Claude Code, 用 20 天跑通 9 个包的 monorepo 工程
前端·人工智能·github
峰向AI14 小时前
做小红书、画信息图、动漫图:这个skill太实用了
github
Cosolar14 小时前
封神级 TTS!VoxCPM2 凭连续表征,玩转多语言合成 + 创意音色 + 无损声纹克隆
人工智能·llm·github
码流怪侠14 小时前
【GitHub】andrej-karpathy-skills:让 AI 编程助手告别三大通病
人工智能·程序员·github
码流怪侠14 小时前
【GitHub】OpenClaw:开源个人AI助手的新标杆
人工智能·程序员·github