这种情况适用于用通一台电脑连接不同的仓库
1.生成A仓库需要的key
ssh-keygen -t rsa -C “email@funplus.com” -f ~/.ssh/funplus_rsa
2.生成B仓库需要的key
ssh-keygen -t rsa -C “email@nextentertain.com” -f ~/.ssh/nextentertain_rsa
生成ssh key同时都会生成一个私钥和一个公钥,用于非对称加密。我们需要在对应仓库设置的key都是公钥,也就是.pub结尾的文件内容
3.查看.ssh目录
ls ~/.ssh/,理论上此时应该会存在这些文件
funplus_rsa .pub nextentertain_rsa.pub
funplus_rsa nextentertain_rsa
4.把私钥添加到系统
ssh-add ~/.ssh/funplus_rsa
ssh-add ~/.ssh/nextentertain_rsa
5.修改配置文件
进入~/.ssh目录下
cd ~/.ssh
touch config
open config
打开文件编辑,添加如下内容,相应的host、hostName、key替换成自己需要的
# bitbucket1
Host bitbucket1.com
HostName bitbucket1.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/funplus_rsa
# bitbucket2
Host bitbucket2.com
HostName bitbucket2.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/nextentertain_rsa
以上的host和hostName可以相同,测试连接应该可用了
ssh -T git@bitbucket.com
网友评论