我在一台 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)
该用户可能与 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/