同一台主机两个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
相关推荐
Soari25 分钟前
GitHub 开源项目解析:OpenBMB/VoxCPM —— Tokenizer-Free 多语言语音合成与声音克隆模型
开源·github·语音合成·tts·多语言语音生成
半夜修仙27 分钟前
RabbitMQ常见高级特性
其他·中间件·rabbitmq·github·java-rabbitmq
Soari1 小时前
GitHub 开源项目解析:EveryInc/compound-engineering-plugin —— 让 AI 编程从“一次性生成”走向“持续复利工程”
人工智能·开源·github·claude code
三无推导1 小时前
One API Docker 部署实战:从 0 搭建多模型统一接口管理平台
运维·ubuntu·docker·容器·github·api网关·token管理
darkb1rd2 小时前
GordenPPTSkill:AI 生成 PPT 实战
开源·github·好物分享
lauo2 小时前
从算力消耗到Token生产:ibbot手机如何重构AI时代的移动终端价值范式
人工智能·智能手机·重构·架构·开源·github
Soari2 小时前
GitHub 开源项目解析:supermemoryai/supermemory —— AI 时代的持久记忆引擎
人工智能·github·开源项目·mcp·ai记忆引擎·下文搜索
Soari2 小时前
GitHub 开源项目解析:D4Vinci/Scrapling —— Python 网页抓取与自动化处理工具
python·开源·github·python爬虫·网页抓取·异步抓取
云水一下2 小时前
连接世界——远程仓库与 GitHub 协作实战
git·github
Elastic 中国社区官方博客3 小时前
使用 Elasticsearch 和 GitHub Copilot SDK 构建一个 RAG agent
大数据·人工智能·elasticsearch·搜索引擎·github·全文检索·copilot