使用git时,我们可能一个git客户端使用多个git服务器,比如github,自建gitlab,gitee,为了防止提交混乱,所以需要一一对应生成公私钥。
第一步:
 使用ssh-keygen生成多对密钥对,比如:
 ssh-keygen -t rsa -C '随意注解三者不一样就好' -f ~/.ssh/id_rsa_github
 ssh-keygen -t rsa -C '随意注解三者不一样就好' -f ~/.ssh/id_rsa_gitlab
 ssh-keygen -t rsa -C '随意注解三者不一样就好' -f ~/.ssh/id_rsa_gitee
第二步:
 使用ssh-add录入这三者
ssh-add ~/.ssh/id_rsa_github
ssh-add ~/.ssh/id_rsa_gitlab
ssh-add ~/.ssh/id_rsa_gitee
第三步:
 新建或配置ssh的客户端config文件,就在当前目录下。
 有了配置文件,ssh在建立连接时,就会知道该用对应的公私钥进行连接。
# 通用配置
Host *
    Port 22   
    PreferredAuthentications publickey
    IdentitiesOnly yes
# 配置github.com
Host github.com            
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github
    User 随意
# 配置gitlab
Host xx.xx.xx.xx           
    HostName xx.xx.xx.xx
    IdentityFile ~/.ssh/id_rsa_gitlab
    User 随意
# 配置gitee.com
Host gitee.com            
    HostName gitee.com
    IdentityFile ~/.ssh/id_rsa_gitee
    User 随意
    
第四步:
 把生成的对应公钥中的内容,录入对应平台的ssh公钥中,不同平台略微不同,以gitlab为例:
 
第五步:
 测试链接:
 ssh -T git@github.com
 ssh -T git@xx.xx.xx.xx
 ssh -T git@gitee.com

![[激光原理与应用-82]:激光器研发常见难题](https://img-blog.csdnimg.cn/direct/82855060120e4189829dadfed119eaec.png)
















