第一步:
打开GIT BASH(可以搜索git bash 然后打开)
第二步:
生成第一个ssh key(如:github)
$ ssh-keygen -t rsa -C"email"
(email是你github的邮箱)
然后提示你保存key,可以写成 (路径/.ssh/id_rsa_github) ,回车,再回车,再回车 就会生成出现id_rsa_github和id_rsa_github.pub两个文件
第三步:
生成第二个ssh key(如:githlab)
$ ssh-keygen -t rsa -C"email"
(email是你github的邮箱)
然后提示你保存key,可以写成 (路径/.ssh/id_rsa_gitlab) ,回车,再回车,再回车 就会生成出现id_rsa_gitlab和id_rsa_gitlab.pub两个文件
第四步:
在 ~/.ssh 目录下新建一个config文件
windows下 echo > config
linux下 touch config
然后添加内容
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
第五步 测试
$ ssh -T git@github.com
输出
Hi user! You've successfully authenticated, but GitHub does not provide shell access.