Jenkins出现“Host key verification failed.”
当以 SYSTEM 用户运行 Jenkins 时,如果 git lfs 会出现类似以下错误:
git checkout -f 816256345f3bcf695026bcbe8dbfec9df45e1d86 # timeout=10 FATAL: Could not checkout 816256345f3bcf695026bcbe8dbfec9df45e1d86 hudson.plugins.git.GitException: Command "git checkout -f 816256345f3bcf695026bcbe8dbfec9df45e1d86" returned status code 128: stdout: stderr: Downloading src/xxx.dwg (1.3 MB) Error downloading object: src/xxx.dwg (1f77e68): Smudge error: Error downloading src/xxx.dwg (1f77e6865a675454532f4f2e9d8ff976b01e3e410a92dc115ed52518c43d5e1b): batch request: Host key verification failed.: exit status 255 Errors logged to 'D:\jenkins_home\workspace\\.git\lfs\logs\20221108T214219.8302768.log'. Use `git lfs logs last` to view the log. error: external filter 'git-lfs filter-process' failed fatal: src/xxx.dwg: smudge filter lfs failed at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2736) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$1100(CliGitAPIImpl.java:87) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3058) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to node3 winserver2019 at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1000) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:143) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:129) at com.sun.proxy.$Proxy168.execute(Unknown Source) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1362) at hudson.scm.SCM.checkout(SCM.java:540) at hudson.model.AbstractProject.checkout(AbstractProject.java:1239) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:647) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:519) at hudson.model.Run.execute(Run.java:1899) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449) Caused: hudson.plugins.git.GitException: Could not checkout 816256345f3bcf695026bcbe8dbfec9df45e1d86 at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$9.execute(CliGitAPIImpl.java:3082) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:158) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:151) at hudson.remoting.UserRequest.perform(UserRequest.java:211) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:376) at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:125) at java.base/java.lang.Thread.run(Thread.java:833)
原因是 Jenkins 的 Git Client 没有把 known_hosts 的 ssh 公匙指纹和私匙传到给 git lfs。这只能在用户目录下的 .ssh 目录下加 known_hosts 的 ssh 公匙指纹和私匙。
SYSTEM 用户的用户目录是在“C:\Windows\System32\config\systemprofile”,在资源管理器里无法直接见 .ssh 目录,只能在命令提示符下进行建立。
.ssh 目录建好了之后,把 known_hosts 和私匙加上就可以了。
ssh 公匙指纹可以通过 ssh-kenscan 命令得到。例如:
C:\Windows\system32>ssh-keyscan bitbucket.org # bitbucket.org:22 SSH-2.0-conker_44eee6a33e 00a7cd581b86 bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== # bitbucket.org:22 SSH-2.0-conker_44eee6a33e 7d0f1d34a6ad # bitbucket.org:22 SSH-2.0-conker_44eee6a33e 5b0d39b89c09
还有一种出错例子是这样的:
> git fetch --tags --force --progress -- ssh://git@git.example.com/example.git +refs/heads/*:refs/remotes/origin/* # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from ssh://git@git.example.com/example.git at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1002) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1244) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1308) at hudson.scm.SCM.checkout(SCM.java:540) at hudson.model.AbstractProject.checkout(AbstractProject.java:1241) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:521) at hudson.model.Run.execute(Run.java:1900) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449) Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- ssh://git@git.example.com/example.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: No ED25519 host key is known for [git.example.com]:22 and you have requested strict checking. Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2734) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2111) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:87) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:623) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:158) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:151) at hudson.remoting.UserRequest.perform(UserRequest.java:211) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:377) at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:125) at java.base/java.lang.Thread.run(Thread.java:833) Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to node3 winserver2019 at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356) at hudson.remoting.Channel.call(Channel.java:1000) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:143) at jdk.internal.reflect.GeneratedMethodAccessor218.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:129) at com.sun.proxy.$Proxy123.execute(Unknown Source) at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1000) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1244) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1308) at hudson.scm.SCM.checkout(SCM.java:540) at hudson.model.AbstractProject.checkout(AbstractProject.java:1241) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:521) at hudson.model.Run.execute(Run.java:1900) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:107) at hudson.model.Executor.run(Executor.java:449) ERROR: Error fetching remote repo 'origin'