一、生产密钥

1.1、打开命令行,生产第 1 个 ssh key。

1
ssh-keygen -t rsa -C "xx@qq.com"

1.2、打开命令行,生产第 2 个 ssh key。

1
ssh-keygen -t rsa  -f ~/.ssh/id_rsa_other -C "xx@qq.com"

1.3、在目录~/.ssh/下创建 config 文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
User xx

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_other
User xx

二、阿里云多个账号配置

2.1、修改 config 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 配置codeup.aliyun.com,这个正常使用
host codeup.aliyun.com
HostName codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_ali1
User xxx
IdentityAgent none
IdentitiesOnly yes

# 配置 codeup.aliyun.com
# 使用命令 git clone git@ali2:xxx.git
Host ali2
HostName codeup.aliyun.com
IdentityFile ~/.ssh/id_rsa_ali2
User xxx
IdentityAgent none
IdentitiesOnly yes

# 配置 codeup.aliyun.com
# 使用命令 git clone git@ali3:xxx.git
Host ali3
HostName codeup.aliyun.com
IdentityFile ~/.ssh/id_rsa_ali3
User xxx
IdentityAgent none
IdentitiesOnly yes