git 配置多个ssh

1、如果配置一个ssh-key,直接执行如下命令:
$ssh-****** -t rsa -C "[email protected]",然后在系统盘所在用户文件夹下会生
成一个.ssh文件夹。在文件夹中会生成两个文件, id_rsa和id_rsa.pub
然后在github或者gitLab中配置上ssh
打开git,执行代码测试:ssh -T [email protected] ,测试时会提示是否加入可信任的
host,选择yes

2、如果需要配置多个ssh-key:
①执行下面的命令
$ssh-****** -t rsa -f ~/.ssh/github_rsa -C "[email protected]"
-f后面是手动指定生成的秘钥文件名和所在文件夹,如果没有指定,每次生成的新秘
钥都会覆盖原有的。

②在.ssh文件夹中创建config,并写入一下内容
#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa

#gitlab
Host 192.168.6.21
HostName 192.168.6.21
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_rsa