我是靠谱客的博主 包容茉莉,最近开发中收集的这篇文章主要介绍使用SpringCloudConfig连接git报错Cannot clone or checkout repository:xxx,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

配置中心使用 git@github.com:用户名/仓库名.git 作为uri地址时,配置中心客户端访问报错

由于访问git时,使用https(例如:https://github.com/用户名/仓库地址.git)的uri访问不用进行验证,但是使用ssh(例如:git@github.com:用户名/仓库地址.git)的uri访问时需要进行验证,所以需要修改一下配置中心的配置文件

参考文档:官方文档

Git SSH configuration using properties
By default, the JGit library used by Spring Cloud Config Server uses SSH configuration files such as ~/.ssh/known_hosts and /etc/ssh/ssh_config when connecting to Git repositories by using an SSH URI. In cloud environments such as Cloud Foundry, the local filesystem may be ephemeral or not easily accessible. For those cases, SSH configuration can be set by using Java properties. In order to activate property-based SSH configuration, the spring.cloud.config.server.git.ignoreLocalSshSettings property must be set to true, as shown in the following example:

  spring:
    cloud:
      config:
        server:
          git:
            uri: git@gitserver.com:team/repo1.git
            ignoreLocalSshSettings: true
            hostKey: someHostKey
            hostKeyAlgorithm: ssh-rsa
            privateKey: |
                         -----BEGIN RSA PRIVATE KEY-----
                         MIIEpgIBAAKCAQEAx4UbaDzY5xjW6hc9jwN0mX33XpTDVW9WqHp5AKaRbtAC3DqX
                         IXFMPgw3K45jxRb93f8tv9vL3rD9CUG1Gv4FM+o7ds7FRES5RTjv2RT/JVNJCoqF
                         ol8+ngLqRZCyBtQN7zYByWMRirPGoDUqdPYrj2yq+ObBBNhg5N+hOwKjjpzdj2Ud
                         1l7R+wxIqmJo1IYyy16xS8WsjyQuyC0lL456qkd5BDZ0Ag8j2X9H9D5220Ln7s9i
                         oezTipXipS7p7Jekf3Ywx6abJwOmB0rX79dV4qiNcGgzATnG1PkXxqt76VhcGa0W
                         DDVHEEYGbSQ6hIGSh0I7BQun0aLRZojfE3gqHQIDAQABAoIBAQCZmGrk8BK6tXCd
                         fY6yTiKxFzwb38IQP0ojIUWNrq0+9Xt+NsypviLHkXfXXCKKU4zUHeIGVRq5MN9b
                         BO56/RrcQHHOoJdUWuOV2qMqJvPUtC0CpGkD+valhfD75MxoXU7s3FK7yjxy3rsG
                         EmfA6tHV8/4a5umo5TqSd2YTm5B19AhRqiuUVI1wTB41DjULUGiMYrnYrhzQlVvj
                         5MjnKTlYu3V8PoYDfv1GmxPPh6vlpafXEeEYN8VB97e5x3DGHjZ5UrurAmTLTdO8
                         +AahyoKsIY612TkkQthJlt7FJAwnCGMgY6podzzvzICLFmmTXYiZ/28I4BX/mOSe
                         pZVnfRixAoGBAO6Uiwt40/PKs53mCEWngslSCsh9oGAaLTf/XdvMns5VmuyyAyKG
                         ti8Ol5wqBMi4GIUzjbgUvSUt+IowIrG3f5tN85wpjQ1UGVcpTnl5Qo9xaS1PFScQ
                         xrtWZ9eNj2TsIAMp/svJsyGG3OibxfnuAIpSXNQiJPwRlW3irzpGgVx/AoGBANYW
                         dnhshUcEHMJi3aXwR12OTDnaLoanVGLwLnkqLSYUZA7ZegpKq90UAuBdcEfgdpyi
                         PhKpeaeIiAaNnFo8m9aoTKr+7I6/uMTlwrVnfrsVTZv3orxjwQV20YIBCVRKD1uX
                         VhE0ozPZxwwKSPAFocpyWpGHGreGF1AIYBE9UBtjAoGBAI8bfPgJpyFyMiGBjO6z
                         FwlJc/xlFqDusrcHL7abW5qq0L4v3R+FrJw3ZYufzLTVcKfdj6GelwJJO+8wBm+R
                         gTKYJItEhT48duLIfTDyIpHGVm9+I1MGhh5zKuCqIhxIYr9jHloBB7kRm0rPvYY4
                         VAykcNgyDvtAVODP+4m6JvhjAoGBALbtTqErKN47V0+JJpapLnF0KxGrqeGIjIRV
                         cYA6V4WYGr7NeIfesecfOC356PyhgPfpcVyEztwlvwTKb3RzIT1TZN8fH4YBr6Ee
                         KTbTjefRFhVUjQqnucAvfGi29f+9oE3Ei9f7wA+H35ocF6JvTYUsHNMIO/3gZ38N
                         CPjyCMa9AoGBAMhsITNe3QcbsXAbdUR00dDsIFVROzyFJ2m40i4KCRM35bC/BIBs
                         q0TY3we+ERB40U8Z2BvU61QuwaunJ2+uGadHo58VSVdggqAo0BSkH58innKKt96J
                         69pcVH/4rmLbXdcmNYGm6iu+MlPQk4BUZknHSmVHIFdJ0EPupVaQ8RHT
                         -----END RSA PRIVATE KEY-----

实例:

spring:
  application:
    name:  cloud-config-center #注册进Eureka服务器的微服务名
  cloud:
    config:
      label: master
      server:
        git:
          uri: git@github.com:用户名/仓库地址.git #GitHub上面的git仓库名字
          ####搜索目录
          search-paths:
            - springcloud-config
          strict-host-key-checking: false
          ignore-local-ssh-settings: true
          private-key: |
            -----BEGIN RSA PRIVATE KEY-----
            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
            -----END RSA PRIVATE KEY-----

找不到key?

1、首先确保本地已经有git的环境了

2、查看文件夹:C:Users主机名.ssh  是否有此文件夹,若没有可以手动创建或者在任意目录执行以下操作

3、打开Git Bash

4、执行命令:ssh-keygen -t rsa -C "xxxxx@xxx.com" 其中xxxxx@xxx.com是你的github账户,然后直接enter,之后会提示输入秘密,可输可不输直接回车即可。

5、执行完成后,在C:Users主机名.ssh 目录下就会生成如下文件夹

6、其中id_rsa就是ssh-key,此时需要将密钥填写到自己的github中,密钥是在文件id-rsa.pub中,以邮箱结尾的一段密钥

7、打开github,进入settings/SSH and GPG keys,点击New SSH key

8、将id_rsa.pub中的密钥填写到其中,title随便写,见名知意即可

9、然后添加即可,此时在springcloud的配置中心中就可以添加密钥了,如最上面所示,密钥内容是文件id_rsa中的内容,注意:密钥内容是以-----BEGIN RSA PRIVATE KEY-----开头,-----END RSA PRIVATE KEY-----结尾的,这两个内容也是密钥的内容不可省略

 

 

 

最后

以上就是包容茉莉为你收集整理的使用SpringCloudConfig连接git报错Cannot clone or checkout repository:xxx的全部内容,希望文章能够帮你解决使用SpringCloudConfig连接git报错Cannot clone or checkout repository:xxx所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部