【问题标题】:Gitlab connectivity from Go CI/CD来自 Go CI/CD 的 Gitlab 连接
【发布时间】:2019-02-02 17:04:59
【问题描述】:

我正在尝试使用 GO CI/CD 管道从 gitlab 克隆一个项目。我做了如下步骤,

  1. 我已经有 ssh 密钥,已添加到 gitlab。
  2. 尝试从我的本地机器克隆,我可以使用“git clone”命令进行克隆
  3. 我还尝试使用命令“git clone”在 Go-agent 服务器上克隆项目。
  4. 克隆项目后,我打开了 ssh 文件夹并使用一些密钥修改了“known_hosts”文件。所以我将 ssh 文件夹放在“C:\Windows\System32\config\systemprofile”位置,因为 GO-CD 管道只在那里查看。
  5. 但每当我尝试测试管道连接时,它都会显示拒绝访问。以下是错误

Repository ssh://git@gitlab.demo.com/exampleproject/someproject.git not found! : 
Error performing command: --- Command ---
git ls-remote ssh://git@gitlab.demo.com/exampleproject/someproject.git
--- Environment ---
{}
--- INPUT ----


--OUTPUT ---

--- ERROR ---
STDERR: Host key verification failed.
STDERR: fatal: Could not read from remote repository.
STDERR: 
STDERR: Please make sure you have the correct access rights
STDERR: and the repository exists.

我也尝试运行命令ssh -T git@gitlab.demo.com,但它显示“权限被拒绝(公钥)。”。谁能告诉我为什么?我缺少什么配置?

【问题讨论】:

    标签: continuous-integration gitlab


    【解决方案1】:

    如果您使用默认名称 id_rsa 创建了密钥,请尝试将其复制到 C:\Windows\SysWOW64\config\systemprofile.ssh (https://startbigthinksmall.wordpress.com/2012/04/26/how-to-authorize-local-system-account-for-openssh/)。

    如果在重新启动服务后这不起作用,或者如果您认为需要使用多个身份,以下可能会有所帮助:

    我假设重新启动您的 Go-CD 服务器服务不起作用,并且您正在使用默认的本地系统帐户运行您的 Go 服务器服务。我更喜欢使用域帐户运行,因为这有助于解决一些棘手的权限问题和这种类型的配置。先看看这个答案:.ssh/config file for windows (git)

    如果您在服务帐户下运行,您的 RSA 密钥通常会写入 ~/.ssh/ - 这很可能转换为:C:/Users/your-account/.ssh。如果此文件夹不存在,请在管理员模式下打开命令窗口,cd 到您的帐户文件夹并运行 mkdir .ssh。

    当 Go-CD 使用 SSH 连接到 Git 存储库时,它会使用 git 命令,而这些命令又会调用 ssh 命令。对于所有这些层,有许多方法可以配置要使用的身份。首先要阅读的文章是 (https://medium.com/@pinglinh/how-to-have-2-github-accounts-on-one-machine-windows-69b5b4c5b14e) 请注意 sshCommand 如何通过指定 rsa 文件的文件路径来覆盖 git 将使用的身份。

    与其直接编辑 git 配置,我认为编辑全局 ssh 配置会更好地处理多个身份/密钥,并且 Go-CD 更容易处理。见https://www.ssh.com/ssh/config/。默认情况下,ssh 配置文件位于 ~/.ssh/config。如果没有,请创建一个名为 config 的文本文件,不带任何扩展名。编辑该文件并添加一个条目,以指定您的身份文件(RSA 密钥)或文件的路径。例如(https://superuser.com/questions/366649/ssh-config-same-host-but-different-keys-and-usernames):

      Host github_username1
        Hostname github.com
        User git
        IdentityFile ~/.ssh/rsa_1
      Host github_username2
        Hostname github.com
        User git
        IdentityFile ~/.ssh/rsa_2
    

    这将为您的材料建立一个主机别名。因此,如果您使用的是上面显示的第二个主机,则可以使用 git@github_username2/pathtorepo,而不是使用 git@gitlab.com/pathtorepo。

    进行更改后,请务必让您的 Go-CD 服务退回,以防万一。

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 2021-08-21
      • 2022-11-02
      • 2021-11-29
      • 2020-07-03
      • 2022-08-10
      • 2019-08-07
      • 2022-12-10
      • 2020-10-30
      相关资源
      最近更新 更多