Spring Cloud / Jgit / Github SSH失败

问题描述 投票:1回答:1
  • Windows 10 Pro x64
  • JDK 11.0.6
  • spring-cloud-config-server 2.2.2.RELEASE

我正在设置Spring Cloud Config服务器。在文件系统后端正常工作。在https / basic auth github后端上可以正常工作。现在,我正在尝试将其设置为使用SSH,因此不必在配置文件中放入用户名和密码。

据我了解,Spring Cloud Config / jgit将使用所有默认的SSH设置,对吗?我已经完成以下工作:

  1. ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"-提取了所有默认文件,没有密码。文件在C:\ Users \ xxx.ssh中创建。
  2. 打开的c:\ users \ xxx.ssh \ id_rsa.pub,全部选中,c&p到github
  3. 运行git clone [email protected]:xxx/Config.git,将SHA256指纹复制到是/否/指纹提示中,克隆成功
  4. 编辑known_hosts并删除了IP,所以现在它只读取github.com ssh-rsa AAAA...
  5. application.properties:

    [email protected]:xxx / Config.git

    spring.cloud.config.server.git.clone-on-start = true

    spring.cloud.config.server.git.strict-host-key-checking = false

    spring.cloud.config.server.git.skip-ssl-validation = true

这导致:

Caused by: com.jcraft.jsch.JSchException: Auth fail
    at com.jcraft.jsch.Session.connect(Session.java:519) ~[jsch-0.1.54.jar:na]
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:146) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]
    ... 31 common frames omitted

为什么我的身份验证失败?

github ssh spring-cloud spring-cloud-config jgit
1个回答
0
投票

一个可能的原因是该服务器以管理员身份而不是您的常规用户帐户运行,这意味着它将找不到%USERPROFILE%\id_rsa

OP SledgeHammer确认in the comments

Jgit在Windows上对HOMEDRIVEHOMEPATH起作用。我的公司将它们重新映射到P:驱动器(尽管它没有重新映射USERPROFILE)。openssh工具(以及git本身)可针对USERPROFILE使用。

这意味着Jsch将需要.ssh中的P:\


另一个原因是format of the private key(尝试使用旧的OpenSSH格式生成的私钥进行测试)

最后,double-check the URI used

研究了jgit API之后,我解决了这个问题。Spring Cloud Config文档中的URI不正确。该文档列出了要使用的格式

git@host:port/repo1.git

它应该是

ssh://git@host:port/repo1.git

因此,在我的情况下,一旦我将其更改为ssh:// git @ mygit:2222 / secops / secrets.git,它就会起作用。>

((您不需要端口2222,只需使用'/'而不是':']] >>

© www.soinside.com 2019 - 2024. All rights reserved.