Git之使用多个ssh

1、取消全局绑定的账号

1
git config –global –unset user.name
1
git config –global –unset user.emai
git全局配置

2、生成多个 ssh key

1
ssh-keygen -t rsa -C "your_emial@examle.com"

创建ssh key ssh key

3、在 github、码云等平台绑定创建的 ssh key

4、 在.ssh/config 文件中进行配置

[注释]:若没有 config 文件,在.ssh 文件中创建

1
touch 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
27
28

// 配置

// Host随便写,最后测试连接的名字

// HostName写对应的地址(如果是公司的域名:110.123.123那么这⾥就是110.123.123)

// IdentityFile 你⽣成的ssh key名字


Host github.com

HostName github.com

PreferredAuthentications publickey

IdentityFile ~/.ssh/id_rsa

# gitee 账号邮箱

Host su.gitee.com

HostName gitee.com

PreferredAuthentications publickey

IdentityFile ~/.ssh/id_rsa_2

5、 添加刚刚创建的多个ssh key到系统

1
ssh-add ~./ssh/id_rsa_2

6、 测试

1
2
3
4
5
# 测试 Github链接是否成功
# 出现
# `Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access.` 即可

ssh -T git@su.github.com
测试ssh是否配置成功

Git之使用多个ssh
https://www.gongyibai.site/Git之使用多个ssh/
作者
爱吃糖醋排骨的苏小妍.
发布于
2024-11-26 17:10:55
更新于
2024-12-16 16:00:28
许可协议