同一台主机两个github账号切换使用

同一主机两个github账号切换使用

可能某些原因,我们需要在公司与个人之间切换相关的开发者账号。如同一台主机两个github账号

此为windows环境

操作步骤如下

首先,创建2组 公私钥

默认用户目录 ~/.ssh

bash 复制代码
$ ssh-keygen -t ed25519 -C "[email protected]"
Enter file in which to save the key (~/.ssh/id_ed25519):
# 回车, 默认生成 id_ed25519 和 id_ed25519.pub

$ ssh-keygen -t ed25519 -C "[email protected]"
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 [email protected]
github-sec testeru [email protected]
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 [email protected]
相关推荐
萌萌哒草头将军1 小时前
🎮 📺 ⚽️ ShadPS4:一款可以免费玩血源诅咒等有你的开源 PS4 模拟器
github
草梅友仁4 小时前
MCP 协议与古茗排队事件解析 | 2025 年第 16 周草梅周报
github·aigc·mcp
Fishermen_sail5 小时前
如何写 commit message?
git·github
我是哪吒7 小时前
分布式微服务系统架构第113集:CondFuture,网关服务器、Cassandra数据库、Redis缓存、Kafka消息队列、Elasticsearch客户端
后端·面试·github
Bryan_Long2 天前
Git 命令行操作提交至远程仓库
git·github
muyouking112 天前
3.Rust + Axum 提取器模式深度剖析
前端·rust·github
小华同学ai2 天前
15.4K Star!Vercel官方出品,零基础构建企业级AI聊天机器人
github
三道杠卷胡2 天前
【AI News | 20250417】每日AI进展
人工智能·pytorch·python·语言模型·github
绝无仅有2 天前
使用 Docker 安装 Elastic Stack 并重置本地密码
后端·面试·github
uhakadotcom2 天前
Langflow:零基础快速上手AI流程可视化开发工具详解与实战案例
后端·面试·github