Spring Cloud Config 无法使用 ssh 密钥克隆私有 bitbucket 存储库
Spring Cloud Config cannot clone private bitbucket repository using ssh key
我在 Linux(arch)上,尝试使用 ssh 密钥配置 Spring Cloud Config tutorial 和私有 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"
创建的。 public 密钥已正确添加到 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 密钥,我怎样才能让它工作?
终于成功了!
这个问题: 为我指出了正确的方向。我调试了 JschConfigSessionFactory
class 并发现当未提供用户名和密码时它会从 ~/.ssh/config
.
中的默认配置文件中获取配置
因此,我所要做的就是将以下内容添加到我的 ~/.ssh/config 文件中:
~/.ssh/config
Host bitbucket.org
User TarekSaid
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/bitbucket_rsa
现在可以使用了。
我在 Linux(arch)上,尝试使用 ssh 密钥配置 Spring Cloud Config tutorial 和私有 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"
创建的。 public 密钥已正确添加到 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 密钥,我怎样才能让它工作?
终于成功了!
这个问题:JschConfigSessionFactory
class 并发现当未提供用户名和密码时它会从 ~/.ssh/config
.
因此,我所要做的就是将以下内容添加到我的 ~/.ssh/config 文件中:
~/.ssh/config
Host bitbucket.org
User TarekSaid
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/bitbucket_rsa
现在可以使用了。