代码之家  ›  专栏  ›  技术社区  ›  JanMensch

带有SSH主机别名的git克隆

  •  1
  • JanMensch  · 技术社区  · 6 年前

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

    假设我们的git repo url如下:

    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/配置 使用SSH密钥)和repo顺利签出。我有一种不安的感觉,git不知怎么地无法解析主机名别名。

    你知道发生了什么吗?跑步 git clone --progress --verbose ... 遗憾的是没有提供更多的信息。

    0 回复  |  直到 6 年前
    推荐文章