linux - 无法从 Jenkins 访问 git repo

标签 linux git github jenkins ssh

我在一台 Linux 机器上配置了 Jenkins,我的 git 仓库在另一台 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 key 都存在于彼此的 .ssh/known_hosts 文件夹中。
我也可以从 repo 中提取或克隆代码到 Jenkins 系统中的文件夹中。那么为什么 Jenkins 不能接受呢?
我也试过 URL user@ip:/fullpath/to/repo

最佳答案

您需要确保 Jenkins 以正确的用户身份运行(在 ~/.ssh/id_rsa(.pub)

中拥有 key 的用户)

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

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

Does it being a bare repo make any difference or change in the URL?

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

关于linux - 无法从 Jenkins 访问 git repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35173677/

相关文章:

git - 将单个文件从克隆的仓库推送到 fork 的仓库

r - 在 R 中安装 lightgbm

github - 如何在没有子域的情况下激活 GitHub 中的页面机制?

git - 如何在 Windows 上安装 GitWeb?

git grep 仅在未跟踪的文件中

linux - 从 R 调用 Linux 函数

linux - 如何检查 UPnP 服务器是否正在运行?

linux - 如何将发布文件转换为 git repo

mysql:改变大表,磁盘空间问题

linux - yarn 节点管理器未启动。没有错误