Spring Cloud Config无法使用ssh密钥克隆私有Bitbucket存储库 [英] Spring Cloud Config cannot clone private bitbucket repository using ssh key

查看:39
本文介绍了Spring Cloud Config无法使用ssh密钥克隆私有Bitbucket存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux(ARCH)上,尝试使用ssh密钥通过私有的Bitbucket git存储库tutorial配置Spring Cloud Config,但一直收到错误:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is java.lang.IllegalStateException: Cannot
clone or checkout repository] with root cause com.jcraft.jsch.JSchException: Auth fail

现在,根据教程,它应该可以工作:

如果您不使用HTTPS和用户凭据,则当您将密钥存储在默认目录(~/.ssh)中并且URI指向SSH位置(例如"git@github.com:configuration/cloud-configuration".)时,SSH也应该开箱即用~/.ssh/KNOWN_HOSTS中的所有密钥都采用"ssh-rsa"格式,这一点很重要。不支持新的"ecdsa-sha2-nistp256"格式。存储库是使用JGit访问的,因此您在上面找到的任何文档都应该适用。HTTPS代理设置可以在~/.git/config中设置,也可以通过系统属性(-Dhttps.proxyHost和-Dhttps.proxyPort)以与任何其他JVM进程相同的方式设置。

我在~/.ssh文件夹中确实有一个名为Bitbucket-rsa的私有ssh密钥,它是使用命令ssh-keygen -t rsa -b 4096 -C "my-email@provider.com"创建的。公钥被正确地添加到Bitbucket中,因为我能够从命令行毫无故障地从存储库克隆、拉入和推送。私钥已添加到ssh-agent,且bitbucket.org位于KNOWN_HOSTS文件中。

下面是config-service项目中的bootstrap.yml:

spring:
  application:
    name: config-service
  cloud:
    config:
      server:
        git:
          uri: "git@bitbucket.org:TarekSaid/my-private-repo.git"
server:
  port: 8888

使用带有用户名和密码的https可以工作,但我仍然喜欢使用ssh密钥,如何才能使其工作?

推荐答案

终于成功了!

这个问题:How to use a custom ssh key location with Spring Cloud Config给我指明了正确的方向。我调试了JschConfigSessionFactory类,发现当未提供用户名和密码时,它会从~/.ssh/config中的默认配置文件获取配置。

因此,我所要做的就是将以下内容添加到我的~/.ssh/config文件中:

~/.ssh/config

Host bitbucket.org
  User TarekSaid
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentitiesOnly yes
  IdentityFile ~/.ssh/bitbucket_rsa

现在可以工作了。

这篇关于Spring Cloud Config无法使用ssh密钥克隆私有Bitbucket存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆