git - 使用 GitHub 存储库和 SSH 登录的 Spring Boot 配置服务器

标签 git spring-boot ssh

我一直在尝试在 Spring Boot 中设置一个配置服务器,其配置将从私有(private) Github 存储库提供。之前,使用用户名和密码的配置也可以很好地实现相同的效果。

就像在我的 application.properties 文件中一样,我可以简单地提供如下详细信息:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          username: trolley
          password: strongpassword

但是使用相同的配置,我收到了一封来自 GitHub 的电子邮件,说基于用户名和密码的身份验证已被弃用。 您可以查看此链接以获取更多详细信息。 Token authentication requirements for Git operations

因此,我继续进行基于 SSH 的身份验证。我按照 GitHub 教程创建了一个公钥-私钥对,并成功将其添加到我的 git 存储库中。这是该链接 Connecting to GitHub with SSH

此后,我使用私钥尝试了 SSH 连接并获得了成功的响应。

Hi ankur19030! You've successfully authenticated, but GitHub does not provide shell access

因此,这意味着我使用公钥和私钥的 GitHub 连接设置已完成。现在剩下的就是在 Spring Boot 的 application.yml 文件中配置 Spring Boot 属性 这是我的配置:

spring:
  cloud:
    config:
      server:
        git:
          uri: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e39372a1e39372a362b3c703d3133" rel="noreferrer noopener nofollow">[email protected]</a>:ankur19030/cosylab_config.git
          ignoreLocalSshSettings: true
          privateKey: |
                         -----BEGIN OPENSSH PRIVATE KEY-----
                         MY SSH PRIVATE KEY
                         -----END OPENSSH PRIVATE KEY-----

现在,我在 spring boot 中遇到以下错误:

  Description:

Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.server.git' to org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties failed:

    Reason: Property 'spring.cloud.config.server.git.privateKey' is not a valid private key


Action:

Update your application's configuration

我不明白,当我使用相同的 key 在终端上成功测试 ssh 连接时,为什么私钥显示为无效。

最佳答案

this tutorial中所示,私钥格式可能是旧的 PEM 格式,而不是 OPENSSH 格式。

尝试重新生成旧格式的 key ,看看它是否有效:

ssh-keygen -P "" -m PEM -t rsa -f secondKey

复制secondKey的内容(首先使用 ssh -Tv -i secondKey <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385f514c785f514c504d5a165b5755" rel="noreferrer noopener nofollow">[email protected]</a> 进行测试后)

关于git - 使用 GitHub 存储库和 SSH 登录的 Spring Boot 配置服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65966411/

相关文章:

git - 为什么 git mergetool 在 vi​​mdiff 中打开 4 个窗口? (我希望 3)

java - 为每个配置文件组配置 Spring Cloud 配置服务器

spring - Kotlin - lateinit TestRestTemplate 没有为集成测试初始化

Git 子模块和 ssh 访问

asp.net - 如何使用 GIT 和 ex 部署 ASP.NET (mvc) 站点。 beanstalkapp.com 通过 FTP?

Git 一直提示我输入密码

git - git rebase 错误 ("could not apply...")

java - 在测试类中设置字段时出现 NullPointerException

linux - 从 Windows 命令提示符进行 ssh 时主机 key 验证失败?

linux - 几个特殊IP通过ssh连接到服务器