git 詹金斯发现找不到 ssh 密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12097982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:24:44  来源:igfitidea点击:

Jenkins finds cannot find ssh key

javagitubuntubitbucket

提问by david99world

I've got an ssh key in ~/.ssh/id_rsa.pub when I login as the jenkins user.

当我以 jenkins 用户身份登录时,我在 ~/.ssh/id_rsa.pub 中有一个 ssh 密钥。

I've imported this into bitbucket correctly and it has accepted the key.

我已将其正确导入到 bitbucket 中,并且它已接受密钥。

When I try to do a git clone (to the correct URL) I still get....

当我尝试执行 git clone(到正确的 URL)时,我仍然得到....

Building in workspace /var/lib/jenkins/jobs/Google adwords/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Google adwords/workspace - hudson.remoting.LocalChannel@2c473996
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:DAVID99WORLD/assessme.git
hudson.plugins.git.GitException: Could not clone [email protected]:DAVID99WORLD/assessme.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:268)
    at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1122)
    at hudson.plugins.git.GitSCM.invoke(GitSCM.java:1064)
    at hudson.FilePath.act(FilePath.java:842)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1064)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin [email protected]:DAVID99WORLD/assessme.git /var/lib/jenkins/jobs/Google adwords/workspace" returned status code 128:
stdout: Cloning into '/var/lib/jenkins/jobs/Google adwords/workspace'...

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

Does anyone know of a reason why this would occur? According to the documentation I've read ~/.ssh is the correct directory as the jenkins user for this file to exist.

有谁知道为什么会发生这种情况?根据我读过的文档, ~/.ssh 是作为 jenkins 用户存在的正确目录。

EDIT : My jenkins user does not have a known_hosts file in ~/.ssh but my root level ones do - should it? I can do a clone with my jenkins user just fine and it doesn't mention the host at all as jenkins user.

编辑:我的 jenkins 用户在 ~/.ssh 中没有 known_hosts 文件,但我的根级用户有 - 应该吗?我可以用我的 jenkins 用户做一个克隆就好了,它根本没有提到主机作为 jenkins 用户。

采纳答案by Sebi

It is probably not related to the known_hosts file. I think, you have to check that Jenkins is able to read your public SSH key. Therefore, you might want to check that:

它可能与 known_hosts 文件无关。我认为,您必须检查 Jenkins 是否能够读取您的公共 SSH 密钥。因此,您可能需要检查:

  • home defined for Jenkins user in /etc/passwd matches ~/.ssh
  • Jenkins user has access to his home directory (so at least --x--x--x on all dirs above)
  • Jenkins user has access to the id_rsa.pub file
  • Jenkins is actually running with Jenkins user and not e.g. tomcat user
  • 在 /etc/passwd 中为 Jenkins 用户定义的 home 匹配 ~/.ssh
  • Jenkins 用户可以访问他的主目录(所以至少 --x--x--x 在上面的所有目录上)
  • Jenkins 用户可以访问 id_rsa.pub 文件
  • Jenkins 实际上是与 Jenkins 用户一起运行的,而不是例如 tomcat 用户

Also, what happens if you remove your current id_rsa.pub file? Does it complain of not finding a public key to use?

另外,如果您删除当前的 id_rsa.pub 文件会发生什么?它是否抱怨找不到要使用的公钥?