同一台主机两个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
相关推荐
逛逛GitHub2 小时前
GitHub 开源 AI 好玩神器,自动记录你的一天。
前端·github
散峰而望3 小时前
C++入门(算法) - 习题
开发语言·c++·算法·github
mortimer3 小时前
faster-whisper本地转录简单方案
开源·github·openai
OpenTiny社区7 小时前
不止按钮和表格!TinyVue 偷偷上线 Space 组件,直接搞定「弹性+间距」布局
前端·vue.js·github
用户221765927927 小时前
python第三方库可以处理多线程请求接口结果顺序问题?
github
CoderJia程序员甲7 小时前
GitHub 热榜项目 - 日榜(2025-11-11)
ai·开源·大模型·github·ai教程
lkbhua莱克瓦247 小时前
Java入门——Java跨平台的原理
java·开发语言·笔记·github
qq_254674418 小时前
SSL/TLS
网络协议·github·ssl
QT 小鲜肉9 小时前
【Git、GitHub、Gitee】GitLab的概念、注册流程、远程仓库操作以及高级功能详解(超详细)
git·qt·gitee·gitlab·github
CozyOct111 小时前
⚡️2025-11-10GitHub日榜Top5|AI黑客漏洞发现工具
github