git本地配置多个ssh key账户

1.生成不同的key名

github key

ssh-keygen -t rsa -C "example@email.com” -f ~/.ssh/github_id-rsa

gitlab key

ssh-keygen -t rsa -C "examlpe@企业邮箱.com” -f ~/.ssh/gitlab_id-rsa

这样在相应的目录下~/.ssh/   (linux) ,C:\Users\\username\.ssh\  (windows),生成了两种key。

2.给远程仓库配置添加信任ssh key

找到gitlab_id-rsa.pub,复制其中所有内容,找到远程仓库的ssh-key管理,添加上

 

 

 

 

3.配置config
linux配置
# gitlab
Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gitlab_id-rsa
# github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_id-rsa

Windows配置

# 配置github.com
Host github.com                 
    HostName github.com
    IdentityFile C:\\Users\\username\\.ssh\\github_id-rsa
    PreferredAuthentications publickey
 
# 配置gitlab.com
Host gitlab.com 
    HostName gitlab.com
    IdentityFile C:\\Users\\username\\.ssh\\gitlab_id-rsa
    PreferredAuthentications publickey

3.配置远程仓库key,测试ssh key是否通过

 在远程仓库的个人配置中,将key存入,并且使用ssh -T git@github.com,是否会按照用户名验证即可。

posted @ 2020-01-14 21:39  BrokenColor  阅读(601)  评论(0编辑  收藏  举报