如果有自己的github,又有公司的github,怎么同时支持呢?因为git服务器和本地通信是通过ssh来的,需要一对秘钥来保证通讯安全正常。
在mac中,先定为到ssh目录:
cd ~
cd .ssh
在里面添加一个config文件,内容如下:
#git.company.cn
Host git.company.cn
HostName git.company.cn
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gh
其实很简单,就是将需要访问的域名和对应的私钥绑定一下,告诉系统连接某个域名的时候,用哪个私钥。
然后所有的私钥都自定义一个名字,如我这里的id_rsa_gh 是给github使用的私钥。id_rsa_company是给自己公司使用的私钥。这2个文件要分别用ssh keygen生成。将这2个文件放在ssh目录里。 id_rsa.pub这个公钥自己备份保存。
好了,试一下吧!
ssh -T git@github.com