如何配置Bitbucket的ssh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何配置Bitbucket的ssh相关的知识,希望对你有一定的参考价值。

参考技术A 经过鱼嘴分流后进入内江的岷江水,流到飞沙堰这个位置时,在飞沙堰的对面遇到了第二个弯道,形成又一个弯道环流。加上宝瓶口凿出的离堆阻住水流,一部分水流回涌,夹带大量泥沙的底层重水再度被翻到表层,翻越飞沙堰,泻入外江,内江多余的水和泥沙就在这里被排走。剩下的清水则直接冲向离堆,经宝瓶口流向成都平原。经过第二次排沙,能在飞沙堰下面淤积下来的泥沙已经很少,每一年岁修时遵循“深淘滩,低作堰”的原则把这些泥沙淘出来,这样宝瓶口的进水量就始终都可以得到保证。

Spring cloud config server ssh to bitbucket问题

【中文标题】Spring cloud config server ssh to bitbucket问题【英文标题】:Spring cloud config server ssh to bitbucket problem 【发布时间】:2022-01-14 16:31:09 【问题描述】:

我正在尝试使用 ssh 将 spring 云配置服务器连接到 bitbucket 存储库。我发现很多关于需要 rsa 格式的密钥的帖子。我已经确认我使用了正确的密钥格式,并且我已经尝试过 Java 版本 8、15 和 17。

我可以让它与公共存储库和使用带有用户名/密码的 https 的私有存储库一起使用。但是使用私钥总是会给我一个“com.jcraft.jsch.JSchException:发送频道请求失败”的异常

2021-12-09 20:50:02.736  WARN 8 --- [nio-8888-exec-1] o.s.c.c.s.e.EnvironmentController        : Error getting the Environment with name=feedback profiles=development label=null includeOrigin=false

org.springframework.cloud.config.server.environment.NoSuchRepositoryException: Cannot clone or checkout repository: git@bitbucket.org:jimjudd/service-config.git
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.refresh(JGitEnvironmentRepository.java:320) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.getLocations(JGitEnvironmentRepository.java:262) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.getLocations(MultipleJGitEnvironmentRepository.java:139) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository.findOne(AbstractScmEnvironmentRepository.java:55) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.findOneFromCandidate(MultipleJGitEnvironmentRepository.java:188) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.findOne(MultipleJGitEnvironmentRepository.java:178) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository.findOne(CompositeEnvironmentRepository.java:64) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.EnvironmentEncryptorEnvironmentRepository.findOne(EnvironmentEncryptorEnvironmentRepository.java:61) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.EnvironmentController.getEnvironment(EnvironmentController.java:132) [spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.EnvironmentController.defaultLabel(EnvironmentController.java:109) [spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) [spring-core-5.3.13.jar!/:5.3.13]
    at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:485) [spring-cloud-context-3.1.0.jar!/:3.1.0]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.3.13.jar!/:5.3.13]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) [spring-aop-5.3.13.jar!/:5.3.13]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698) [spring-aop-5.3.13.jar!/:5.3.13]
    at org.springframework.cloud.config.server.environment.EnvironmentController$$EnhancerBySpringCGLIB$$92f4d81c.defaultLabel(<generated>) [spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) [spring-web-5.3.13.jar!/:5.3.13]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) [spring-web-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.13.jar!/:5.3.13]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.3.13.jar!/:5.3.13]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.13.jar!/:5.3.13]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.3.13.jar!/:5.3.13]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.13.jar!/:5.3.13]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.13.jar!/:5.3.13]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.13.jar!/:5.3.13]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.55.jar!/:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.55.jar!/:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: org.eclipse.jgit.api.errors.TransportException: git@bitbucket.org:jimjudd/service-config.git: failed to send channel request
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:224) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:303) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:178) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.cloneToBasedir(JGitEnvironmentRepository.java:658) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.copyRepository(JGitEnvironmentRepository.java:633) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.createGitClient(JGitEnvironmentRepository.java:616) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.refresh(JGitEnvironmentRepository.java:296) ~[spring-cloud-config-server-3.1.0.jar!/:3.1.0]
    ... 69 common frames omitted
Caused by: org.eclipse.jgit.errors.TransportException: git@bitbucket.org:jimjudd/service-config.git: failed to send channel request
    at org.eclipse.jgit.transport.JschSession$JschProcess.<init>(JschSession.java:167) ~[org.eclipse.jgit.ssh.jsch-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.JschSession.exec(JschSession.java:77) ~[org.eclipse.jgit.ssh.jsch-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:289) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:153) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:142) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:94) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1309) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:213) ~[org.eclipse.jgit-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    ... 75 common frames omitted
Caused by: com.jcraft.jsch.JSchException: failed to send channel request
    at com.jcraft.jsch.Request.write(Request.java:65) ~[jsch-0.1.55.jar!/:na]
    at com.jcraft.jsch.RequestEnv.request(RequestEnv.java:52) ~[jsch-0.1.55.jar!/:na]
    at com.jcraft.jsch.ChannelSession.sendRequests(ChannelSession.java:222) ~[jsch-0.1.55.jar!/:na]
    at com.jcraft.jsch.ChannelExec.start(ChannelExec.java:41) ~[jsch-0.1.55.jar!/:na]
    at com.jcraft.jsch.Channel.connect(Channel.java:152) ~[jsch-0.1.55.jar!/:na]
    at org.eclipse.jgit.transport.JschSession$JschProcess.<init>(JschSession.java:159) ~[org.eclipse.jgit.ssh.jsch-5.12.0.202106070339-r.jar!/:5.12.0.202106070339-r]
    ... 82 common frames omitted

服务器配置非常简单

spring:
  cloud:
    config:
      server:
        git:
          timeout: 30
          uri: "git@bitbucket.org:xyz/abc.git"
#          skip-ssl-validation: true
          ignore-local-ssh-settings: true
#          strictHostKeyChecking: false
#          known-hosts-file: "./known_hosts"
          private-key: |
                        -----BEGIN RSA PRIVATE KEY-----
                        MIIJJgIBAAKCAgEAz8V286zbc5nZ0Z+NTq5JcC2Fx2XNGKee4Lg/NIqa8KUCURMC
                        .
                        .
                        .    
                        -----END RSA PRIVATE KEY-----

未能获得正确的组合。有谁知道我还可以尝试什么?

谢谢

【问题讨论】:

【参考方案1】:

尝试在您的网址前面插入ssh:\\,使其成为uri: ssh://git@bitbucket.org:xyz/abc.git

【讨论】:

是的,我试过了,但是配置服务器不喜欢这样。我收到一个关于错误 URL 的不同错误。【参考方案2】:

我最终得到了一些工作。它不是使用 ssh 而是使用 https,bit bucket 允许您生成一个令牌并在密码字段中使用它而不是密码来进行身份验证。现在必须这样做。

【讨论】:

以上是关于如何配置Bitbucket的ssh的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 SourceTree 配置 Bitbucket 应用程序密码?

如何在同一系统中维护多个具有多个 ssh 密钥的 bitbucket 帐户

多个SSH key对应多个Host: Github, Bitbucket

如何为 Github 帐户和 Bitbucket 公司帐户添加多个 SSH 密钥

Spring cloud config server ssh to bitbucket问题

(git bash) 推送到 bitbucket 忽略 SSH 密钥