栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring Cloud Config下reject HostKey: gitee.com问题,及You‘re using an RSA key withSHA-1问题的解决

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Cloud Config下reject HostKey: gitee.com问题,及You‘re using an RSA key withSHA-1问题的解决

 解决思路如下:

1 修改rsa加密方式,操作步骤如下:

--进入当前用户的home目录
--删除.ssh 目录
$ rm -rvf .ssh

--如果要使用SpringCloudConfig的免密登录,则使用如下命令生成秘钥和公钥
ssh-keygen -m PEM -t rsa -b 4096 -f -C a7810222@qq.com

如果是windows系统,则会在如下图位置生成id_rsa,id_rsa.pub,后两个文件是第一次使用git clone + git地址后自动产生的文件,如果要在SpringCloudConfig中使用默认的系统配置,则需要先git clone一下:

然后需要在gitee或github上配置公钥,具体配置可以参考Git进阶系列2. Gitee以及Github使用详细教程_每天都要努力的小颓废呀的博客-CSDN博客。

之后可能会出现spring cloud ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client问题,因为Spring Cloud Config Server使用org.eclipse.jgit库进行git操作,这里的问题是,该库的版本较久,不支持较新版本的RSA密钥(sha2-256 / sha2-512)。

com.jcraft.jsch有一个分支,实现了Github接受的较新版本的RSA,下面是我做的改动。

对pom.xml进行修改:

      
            org.springframework.cloud
            spring-cloud-config-server
                
            
                
                    com.jcraft
                    jsch
                
            
        

        
            com.github.mwiede
            jsch
            0.2.0
        

 还得添加一个shim配置类来解决这个问题:

package com.hashnode.config;

import com.jcraft.jsch.JSch;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JschConfig {
    //Shim to fix the way jGit configures JSch
    static{
        JSch.setConfig("signature.rsa", "com.jcraft.jsch.jce.SignatureRSA");
    }

}

对applicaiton.yml做如下配置:

server:
  port: 3344

spring:
  application:
    name:  cloud-config-center #注册进Eureka服务器的微服务名
  cloud:
    config:
      server:
        git:
#          以下两步均需要在idea的插件中配置gitee
          # 方式1 通过ssh登录
#          uri: git@github.com:GuoWeiChi/turorial-spring-cloud-config.git #GitHub上面的git仓库名字
          uri: git@gitee.com:codinginn/turorial-spring-cloud-config.git #Gitee上面的git仓库名字
          #          ###搜索目录
          search-paths:
            - turorial-spring-cloud-config
          # 方式2 通过账号登录
#          uri: https://gitee.com/codinginn/turorial-spring-cloud-config.git 
#          search-paths:
#            - turorial-spring-cloud-config
#          username: 你自己的登录用户名
#          password: 登录密码

####读取分支
        label: master



然后即可运行项目,完成访问:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/848198.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号