在一台电脑上同时搭建多个Github账号环境

这篇文件讲解如何在同一台电脑上搭建多个Github账号环境。

搭建环境

  • 打开Git Bash

  • 进入~/.ssh目录

  • 输入命令:
1
2
ssh-keygen -t rsa -C "email@email.com"
  • 提示输入key的名称,输入:
1
2
id_rsa_name(name可以为任意名称,例如ant)
  • 当前目录会生成两个文件:
1
2
3
id_rsa_ant
id_rsa_ant.pub
  • 将公钥添加到Github账号下:将id_rsa_ant.pub的内容复制、粘贴到Github网站上

配置环境

~/.ssh目录下找到config文件,进行编辑:

1
2
3
4
5
6
7
8
9
10
11
12
13
#antmoving(ant.moving@outlook.com) //注解
Host ant.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
User antmoving //Github的账户名称
#fishswimming(bird.flying@outlook.com)
Host bird.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_bird
User fishswimming

使用

1
2
git clone git@bird.github.com:fishswimming/fishswimming.github.io.git