【问题标题】:Not able to access git repo from jenkins无法从 jenkins 访问 git repo
【发布时间】:2016-02-22 14:29:06
【问题描述】:

我在一台 Linux 机器上配置了 Jenkins,而我的 git repo 在另一台 Linux 服务器上。但是当我尝试将 repo 的 URL 提供给 Jenkins 时,我收到以下错误。

Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h ssh://user@ip/~/export1 HEAD" returned status code 128:
stdout: 
stderr: Permission denied, please try again. 
Permission denied, please try again. 
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). 
fatal: Could not read from remote repository.

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

这可能是什么原因?

我发现两个系统的 rsa 密钥都存在于彼此的 .ssh/known_hosts 文件夹中。
我也可以将代码从 repo 拉取或克隆到 Jenkins 系统中的文件夹中。那么为什么詹金斯不能接受呢?
我也试过网址user@ip:/fullpath/to/repo

【问题讨论】:

  • 你试过 user:password@ip:/fullpath/to/repo 吗?
  • 我的仓库是一个带有分支的裸仓库。它是一个简单的 repo 对 URL 有什么影响或改变吗?

标签: linux git github jenkins ssh


【解决方案1】:

您需要确保 Jenkins 以正确的用户身份运行(拥有 ~/.ssh/id_rsa(.pub) 中的密钥的用户

该用户可能与 ssh url 中使用的用户不同:user@ip 表示您正在使用您的公钥在~user/.ssh/authorized_key 中的帐户连接到 ip。

所以 Jenkins 进程必须由拥有私钥和公钥的帐户运行,其公钥在 git 服务器端的~user/.ssh/authorized_key
并且该帐户应该在任何 ssh 尝试之前完成(仅一次)ssh-keyscan -H ip >> ~account/.ssh/known_hosts,以便将 git 服务器 ip 记录为已知主机。

作为一个简单的 repo 是否会对 URL 产生任何影响或更改?

没有。当用作 url 时,裸 repo 文件夹末尾的 .git 是可选的。

【讨论】:

    【解决方案2】:

    除了@VonC 的回复,您还可以使用Credentials plugin 在您的 Jenkins 主机上定义一组凭据,您的 Jenkins 作业将使用这些凭据访问您的 Git 存储库。这允许您以不同于可以访问 Git 存储库的用户的身份运行 Jenkins。

    【讨论】:

      【解决方案3】:

      主要问题是系统的安全性。我没有检查我服务器上的身份验证机制。对 git 服务器的密码身份验证导致了问题,因为 jenkins 机器尝试直接向路径触发 ls-remote。当您在终端上执行相同操作时,系统会提示您输入密码,然后它会接受。当我将密码身份验证和 UsePAM 设置为 no 并在 sshd_config 文件中启用 RSA 身份验证、pubkey 身份验证和授权密钥设置为 yes 并重新启动时,它能够访问 repo 并且我没有收到此错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-07
        • 2022-10-24
        • 2021-11-02
        相关资源
        最近更新 更多