我在 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/