github有两个账号,但是同一个ssh公钥只能添加给一个账号,需要再生成一个密匙后添加。步骤如下:

再添加一个ssh密匙

1、指定邮箱

1
2
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.

2、提示输入生成位置和文件名,取个不同的名称。如: /Users/you/.ssh/id_rsa1

1
Enter file in swhich to save the key (/Users/you/.ssh/id_rsa):

3、输入密码,不用设置,一路回车到完成,生成的文件为:/Users/you/.ssh/id_rsa1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
The key fingerprint is:
SHA256:HlteuP6zblxHGjEFh9hLohazijWnxO/aJx0zimpy0lY your_email@example.com
The key's randomart image is:
+---[RSA 2048]----+
| ++.|
| o oo+.|
| . = ooo|
| = * ...|
| S X . + |
| o E + +o .|
| . + =.o.+. |
| o = o =+o |
| *.. o=Bo |
+----[SHA256]-----+

生成的ssh公钥添加到github

复制出生成的ssh公钥

1
pbcopy < /Users/you/.ssh/id_rsa1.pub

github网站setting的SSH and GPG keys新建一个key粘进去

ssh config文件里添加一个host

ssh目录没config文件,新建一个

1
2
3
4
Host github1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa1

修改仓库地址

第二个账号的git地址中git@github.com都改为github1,如:git@github.com:you/your-repo.git变为github1:you/your-repo.git

添加仓库

1
git remote add origin github1:you/your-repo.git

修改仓库地址

1
git remote set-url origin github1:you/your-repo.git