我一直在尝试在 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/