带有SSH主机别名的git clone

时间:2018-10-19 08:15:18

标签: git github ssh continuous-integration

我当前需要完成以下任务:我们的CI服务器需要使用与主项目存储库不同的SSH(部署/签出)密钥从GitHub访问第二个存储库(GitHub部署密钥仅是单存储库。两个存储库=>同一主机的两个SSH密钥。因此使用别名的想法)。但是,我们目前面临一些问题,我可以确定我只是缺少一个细节。

假设我们的git repo网址如下:

git@gitub.com:myorg/somerepo.git

我们将其更改为:

git@gitub-second-account:myorg/somerepo.git

然后我调整了.ssh/config以使用引入的主机别名github-second-account并将其映射回github.com

# Default GitHub user
Host github.com
 HostName github.com
 AddKeysToAgent yes
 IdentityFile ~/.ssh/id_rsa

# Second account alias
Host gitub-second-account
 HostName github.com
 IdentityFile ~/.ssh/second_id_rsa

我测试了我的设置并运行以下命令:

ssh -T git@github-second-account

GitHub表示一切都很好,并且身份验证成功。大。 (通过-vvv验证使用了正确的SSH密钥。) 但是现在我继续执行以下操作:

git clone git@gitub-second-account:myorg/somerepo.git

并得到一个错误:

ssh: Could not resolve hostname gitub-second-account: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

是的,有一个关于访问权限的警告,我仔细检查了所分配的SSH密钥实际上是否具有权限(通过github.com检出并更改我的.ssh/config以使用该SSH密钥)和回购顺利签出。我感到git无法以某种方式解析主机名别名。

有什么想法吗?可悲的是,运行git clone --progress --verbose ...并没有提供更多信息。

0 个答案:

没有答案