Java Spring Cloud Config无法使用ssh密钥克隆私有bitbucket存储库
我在Linux(arch)上,尝试使用ssh密钥使用私有bitbucket git存储库配置Spring Cloud Config,但我一直收到错误:Java Spring Cloud Config无法使用ssh密钥克隆私有bitbucket存储库,java,spring,bitbucket,ssh-keys,spring-cloud-config,Java,Spring,Bitbucket,Ssh Keys,Spring Cloud Config,我在Linux(arch)上,尝试使用ssh密钥使用私有bitbucket git存储库配置Spring Cloud Config,但我一直收到错误: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Can
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_主机中的所有密钥都采用“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代理,并且bitbucket.org存在于已知的_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
类,发现当未提供用户名和密码时,它会从~/.ssh/config
中的默认配置文件获取配置
因此,我所要做的就是将以下内容添加到我的~/.ssh/config文件中:
~/.ssh/config
现在它工作了。很好的解决方案,对我也很有效!!!但需要注意的是:rsa密钥应该在不使用密码的情况下生成,因为否则密码应该在
spring:cloud:config:server:git:passphrase:myprivatekeypassword
中指定,并且看起来像Host bitbucket.org IdentityFile~/.ssh/private_rsa
就足够了
Host bitbucket.org
User TarekSaid
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/bitbucket_rsa