一个电脑下添加多个gitlab/github账号


首先必须明白:
一个gitlab账号对应一个私钥和密钥。

 一、新建user1的SSH key
ssh-keygen -t rsa -C "[email protected]"
Enter file in which to save the key (/Users/Administrator/.ssh/id_rsa):  /c/Users/Administrator/.ssh/id_rsa_user1

将.ssh/id_rsa_user1.pub文件打开,复制里面的公钥,到gitlab/github的ssh中

密钥添加到SSH agent中
ssh-add ~/.ssh/id_rsa_user1

二、新建user2的SSH key
创建:ssh-keygen -t rsa -C "[email protected]"
Enter file in which to save the key (/Users/Administrator/.ssh/id_rsa): /Users/Administrator/.ssh/id_rsa_user2
将.ssh/id_rsa_user2.pub文件打开,复制里面的公钥,到gitlab/github的ssh中

密钥添加到SSH agent中
ssh-add ~/.ssh/id_rsa_user1


三、编辑/创建.ssh/config
# GitLab.com server
Host user1
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_user1
# GitLab.com server
Host user2
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_user2


四、测试是否成功
ssh -T git@user1
ssh -T git@user2

如果成功,就进行下一步,否则重试上面几个步骤

五、克隆项目
假设原本的ssh地址是:git@ gitlab.com :username1/myproject.git
那么在克隆的时候需要将地址改为:git@ user1 :username1/myproject.git

同理克隆项目2的时候:
假设原本的ssh地址是:git@ gitlab.com :username2/myproject.git
那么在克隆的时候需要将地址改为:git@ user2 :username2/myproject.git


猜你喜欢

转载自blog.csdn.net/qq_32400821/article/details/79349214