同一台主机两个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
相关推荐
aircrushin3 分钟前
英语学废了?这个让10万+用户上瘾的神器,让我2个月从哑巴英语到流利对话!
github
Sirens.1 小时前
Java异常处理解析:从防御式编程到自定义异常类
java·开发语言·笔记·学习·github·javac
Android轮子哥3 小时前
Android 12 SplashScreen 一种另类的适配方案
android·github
chenshiming8024 小时前
在GitHub上创建 Deploy keys 步骤
github
Of Chen5 小时前
github+hexo搭建matery主题的个人博客
github·个人博客
逛逛GitHub6 小时前
让 AI 接管 Windows 和 MacOS,这个 GitHub 开源项目牛啊。
github
BER_c6 小时前
Git 提交历史太乱?教你清理并规范 commit message
github
字节幺零二四7 小时前
累计下载 3000+!我的自制实用工具合集现已同步至 GitHub
github·局域网·转换·传输·字幕
小康小小涵20 小时前
睿抗机器人大赛魔力元宝
python·ubuntu·gitee·github
QT 小鲜肉1 天前
【Linux命令大全】002.文件传输之uucico命令(实操篇)
linux·运维·服务器·chrome·笔记·github