有时候咱们可能须要在同一台电脑上配置多个SSH Key
,好比公司项目使用的是GitHub
,我的开发用的是码云Gitee
。这个时候咱们可能须要有两个SSH Key
,怎么配置呢?git
假设你以前已经生成了一个GitHub
的SSH Key
,能够用命令cat ~/.ssh/id_rsa.pub
查看已经生成的SSH Key
:github
复制命令ssh-keygen -t rsa -C 'xxxxx@youremail.com' -f ~/.ssh/gitee_id_rsa
生成一个Gitee
的SSH Key
,一路回车就能够了(记得把邮箱改为你本身的)。能够看到.ssh
文件夹下面多了两个文件。服务器
使用命令cat ~/.ssh/gitee_id_rsa.pub
查看Gitee
的SSH Key
,复制ssh
开头的那一串公钥,添加到Gitee
仓库。ssh
使用命令touch ~/.ssh/config
,在~/.ssh
文件夹下添加config文件,能够看到文件夹下面多了一个config文件。测试
右键使用记事本打开,复制如下信息添加到config文件保存,其中Host
和HostName
填写git服务器的域名,IdentityFile
填写私钥的路径。spa
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitee_id_rsa # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
使用如下命令分别测试GitHub
和Gitee
,查看SSH Key
是否添加成功。3d
ssh -T git@gitee.com ssh -T git@github.com
看到如下的提示,就表示添加成功,能够拉取、推送代码了。code