【发布时间】:2016-10-20 02:52:07
【问题描述】:
我想在Gitlab 网站上使用 2 个帐户,每个帐户都有不同的 ssh 密钥
我成功生成了密钥并将它们添加到~/.ssh 文件夹中
我创建了~/.ssh/config 文件并使用其中一个,效果很好
我还可以通过编辑~/.ssh/config 文件在两个键之间进行交换
问题是:我想同时使用它们,但是我发现所有关于不同主机的教程:/
其实我的两个账号在同一个主机
如何编辑~/.ssh/config 文件以接受同一主机的两个帐户
注意:我阅读了this question,但我无法从中获得帮助
我的两个帐户是username1 和username2
回购 URL 看起来像:git@gitlab.com:username1/test-project.git
我当前的~/.ssh/config 文件:
Host gitlab.com-username1
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa
Host gitlab.com-username2
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_username2
更新 1:
1) 当我在~/.ssh/config 文件中使用一个键时,一切正常(但每次我想更改我使用的用户时都更新它很无聊)
2) 当我使用这条线时
ssh -T git@gitlab.com-username1
ssh -T git@gitlab.com-username2
它运行良好并返回欢迎信息
从 1) 和 2) 开始,我认为问题肯定来自 ~/.ssh/config 文件,特别是在 Host 变量中
更新 2:(解决)
解决的方法是编辑 .git/config 文件
[remote "origin"]
url = git@gitlab.com:username1/test-project.git
到
[remote "origin"]
url = git@gitlab.com-username1:username1/test-project.git
对username2做同样的事情
【问题讨论】:
-
我读过它,我在谈论不同的帐户,在我的情况下,我想在同一个主机上这样做:/
-
"我想在 Gitlab 网站上使用 2 个账号"???副本使用的是同一个主机(你只需要用gitlab替换github。只有github上有。
-
它使用
github.com和ac2.github.com但在我的情况下同样是gitlab.com没有子域 -
它只是
~/.ssh/config中定义的github.com 的别名。没有ac2.github.com -
好的,但在 gitlab 中它是不同的:/ 无论如何你能帮我如何用 gitlab 做吗?