【问题标题】:Jenkins git authentication failed with correct credentials on WindowsJenkins git 身份验证在 Windows 上使用正确的凭据失败
【发布时间】:2020-12-29 10:07:34
【问题描述】:

我目前在 Windows 10 上使用 Jenkins,并使用 git 作为版本控制系统。 虽然我提供了正确的存储库 URL 和凭据,但我无法使用 jenkins,但出现以下错误。

Failed to connect to repository : Command "git.exe ls-remote -h REPOSITORY_URL HEAD" returned status code 128:
stdout:
stderr: git@URL: Permission denied (publickey).
fatal: Could not read from remote repository.

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

凭据和 URL 似乎没有错,因为此构建之前使用相同的凭据成功。构建成功后唯一的变化是构建脚本中的一行。

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

在我成功使用此脚本后,git 设置一直失败。那条线有问题吗?我该如何解决?

编辑
问题解决了!对于任何有同样问题的人,这是系统用户的问题!由于 ssh 密钥存储在每个用户空间中,所以 jenkins 无法检测到 ssh 密钥的位置。因此,在windows中进入“服务”,将jenkins服务的用户更改为具有正确ssh密钥的用户。它解决了我的问题!

【问题讨论】:

  • 尝试运行C:/Windows/System32/OpenSSH/ssh.exe -T -vv git@URL 直接调用带有详细输出的ssh,然后edit 你的问题包含详细输出。了解 ssh 应该使用什么 ssh 密钥文件进行连接,或者如果您不使用密钥,您将如何进行身份验证也会很有帮助。
  • @Kenster 詹金斯似乎有一些问题。它无法在 System32 中找到 OpenSSH 文件夹,因此我无法使用它登录..
  • @MarcusKim 关于服务帐户的好消息。我已将您的结论包含在答案中。

标签: windows git jenkins ssh credentials


【解决方案1】:

詹金斯似乎有一些问题。
它在 System32 中找不到 OpenSSH 文件夹,因此我无法使用它登录。

这可以解释为什么主 Jenkins 控制器(旧术语中的“主控器”)无法联系 Git 存储库(假设这里有一个 SSH URL,使用技术远程用户帐户“git”)

尝试删除该 git 配置以查看错误是否仍然存在:Git 应该回退到它自己的 ssh.exe,与 Git For Windows 打包在一起。

正如 OP 所指出的,这仅在所述 Jenkins 作为用户帐户而不是 system account 运行时才有效。
只有这样它才能访问%USERPROFILE%\.ssh 文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 2016-05-10
    • 1970-01-01
    • 2022-01-10
    • 2014-10-13
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多