如何同时使用多个公秘钥,比如同时使用github和gitoschina、Gitgafe和csdn
1、创建新的秘钥
- ssh-keygen -t rsa -C 'second@mail.com' -f ~/.ssh/id_rsa_second
2. 在 SSH 用户配置文件 ~/.ssh/config
中指定对应服务所使用的公秘钥名称,如果没有 config 文件的话就新建一个,并输入以下内容:
创建文件: vim ~/.ssh/config
生成后将新的ssh public key添加到内部的gitlab仓库中, 然后在~/.ssh 目录下创建config文件,该文件用于配置私钥对应的服务器。内容如下:
Host git.oschina.net #git.oschina.net
HostName git.oschina.net
User git
Port 22
IdentityFile ~/.ssh/id_rsa_osc
Host github.com #github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host code.youkuaiyun.com #csdn
HostName code.youkuaiyun.com
User git
IdentityFile ~/.ssh/id_rsa_csdn
3. 添加 id_rsa_second.pub
中的内容到 Git网站。
git网站都有说明介绍
4. 最后测试配置文件是否正常工作
ssh -T git@XXXXX.com
如果连接成功的话,会出现以下信息。
Hi USERNAME! You've successfully authenticated
5. 完成
测试通过后,你就可以使用独立的一套公秘钥来使用 GitCafe 了。Enjoy!