同一台主机两个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
相关推荐
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
程序视点1 天前
惊喜升级!Claude 3.7 Sonnet 上线 GitHub Copilot!已全账号开放!
github·claude·github copilot
今晚打老虎z1 天前
MailKit: 在 .NET 中实现高效电子邮件发送与接收
git·github·.net
架构文摘JGWZ1 天前
5个GitHub热点开源项目!!
学习·github·工具
液态不合群2 天前
DeepSeek “源神”启动!「GitHub 热点速览」
github
JNU freshman2 天前
github 推送的常见问题以及解决
git·github
cjchsh2 天前
ctfhub-web信息泄露通关攻略
windows·python·github
五行缺觉3282 天前
ROS ur10机械臂添加140夹爪全流程记录
c++·经验分享·机器人·github·ur机械臂·moveit!
無炆_2 天前
IDEA-插件开发踩坑记录-第五坑-没有飞机场导致无法访问GITHUB导致的讨厌问题
java·github·intellij-idea
cccccchd2 天前
github如何创建空文件夹
github