java - Spring Cloud Config 无法使用 ssh key 克隆私有(private) bitbucket 存储库

标签 java spring bitbucket ssh-keys spring-cloud-config

我在 Linux (arch) 上,尝试按照此 tutorial 配置 Spring Cloud Config使用 ssh key 使用私有(private) bitbucket git 存储库,但我不断收到错误消息:

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

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

If you don’t use HTTPS and user credentials, SSH should also work out of the box when you store keys in the default directories (~/.ssh) and the uri points to an SSH location, e.g. "git@github.com:configuration/cloud-configuration". It is important that all keys in ~/.ssh/known_hosts are in "ssh-rsa" format. The new "ecdsa-sha2-nistp256" format is NOT supported. The repository is accessed using JGit, so any documentation you find on that should be applicable. HTTPS proxy settings can be set in ~/.git/config or in the same way as for any other JVM process via system properties (-Dhttps.proxyHost and -Dhttps.proxyPort).

我在名为 bitbucket-rsa 的 ~/.ssh 文件夹中确实有一个 ssh 私钥,它是使用命令 ssh-keygen -t rsa -b 4096 -C "my-email@provider.com"< 创建的。公钥已正确添加到 Bitbucket,因为我可以从命令行从存储库中克隆、拉取和推送,而不会出现任何问题。私钥已添加到 ssh-agent,并且 bitbucket.org 存在于 known_hosts 文件中。

这是配置服务项目中的 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 key ,我该如何让它工作?

最佳答案

终于成功了!

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

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

~/.ssh/配置

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

现在可以了。

关于java - Spring Cloud Config 无法使用 ssh key 克隆私有(private) bitbucket 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39961969/

相关文章:

java - Web 应用程序上下文中日志实用程序 (log4j) 中 Appender 的工作

java - 使用 JavaFX 增加半径时使 Circle 变圆的问题

java - 尝试从服务帐户将文件 POST 到 Google Cloud Storage 时收到 403(禁止)

java - Spring Security 5.1 - 使用 WebClient 获取客户端凭证流的 token

git - 快速查找 Jira 问题的所有 Bitbucket Pull 请求

java - 从 JSch 中的命令输出中删除 shell 内容(如提示)

java - 无法执行目标 org.springframework.boot :spring-boot-maven-plugin:2. 5.5:run (default-cli)

java - 如何在java中使用CommandLineJobRunner构建多个集成测试用例

ssh - Ansible bitbucket 克隆配置 ssh 错误

git - 带有 Tomcat 的 Jenkins - 无法连接到存储库 : Could not init