三尺非寒 发表于 2024-8-25 21:41:39

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

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

可能某些原因,我们必要在公司与个人之间切换相关的开发者账号。犹如一台主机两个github账号
此为windows环境
操作步骤如下
首先,创建2组 公私钥

默认用户目录 ~/.ssh
$ 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账号分别为
commentusernameemailgithub-oneoneAcconeAcc@aa.ccgithub-sectesterutesteru@xx.cc # 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
备注

   代码修改提交(可能会失败),如失败,设置当前目录下的用户为
$ git config user.name testeru
$ git config user.email testeru@xx.cc

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 同一台主机两个github账号切换利用