我在 Linux (arch) 上,尝试按照本教程配置 Spring Cloud Config ,使用 ssh 密钥使用私有 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
现在,根据教程,它应该可以工作:
如果您不使用 HTTPS 和用户凭据,那么当您将密钥存储在默认目录 (~/.ssh) 中并且 uri 指向 SSH 位置时,SSH 也应该开箱即用,例如“git@github.com:配置/云配置”。~/.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 密钥,我怎样才能使它工作?