SSH

0x00 git 配置多个 SSH

1、生成新的SSH密钥

github

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/github_id_ed25519

gitee

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/gitee_id_ed25519

gitcode

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/gitcode_id_ed25519

2、配置 ssh-config

在 ~/.ssh 目录下创建一个 config 文件,并添加如下内容(其中 Host 和 HostName 填写 git 服务器的域名,IdentityFile 指定私钥的路径):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_ed25519

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_ed25519

# gitcode
Host gitcode.com
HostName gitcode.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitcode_id_ed25519

# atomgit
Host atomgit.com
HostName atomgit.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/atomgit_id_ed25519

3、测试SSH连接

1
2
3
4
5
ssh -T git@gitee.com

ssh -T git@github.com

ssh -T git@gitcode.com