Tar*_*rek 3 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: Cannot
clone or checkout repository] with root cause com.jcraft.jsch.JSchException: Auth fail
Run Code Online (Sandbox Code Playgroud)
现在,根据教程,它应该工作:
如果您不使用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
Run Code Online (Sandbox Code Playgroud)
使用带有用户名和密码的https有效,但我仍然更喜欢使用ssh密钥,我该如何使其工作?
Tar*_*rek 11
终于成功了!
这个问题:如何在Spring Cloud Config中使用自定义ssh密钥位置使我指向正确的方向.我调试了这个JschConfigSessionFactory类,发现当没有提供用户名和密码时,它会从默认的配置文件中获取配置~/.ssh/config.
因此,我所要做的就是将以下内容添加到〜/ .ssh/config文件中:
Host bitbucket.org
User TarekSaid
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/bitbucket_rsa
Run Code Online (Sandbox Code Playgroud)
现在它正在运作.
| 归档时间: |
|
| 查看次数: |
6272 次 |
| 最近记录: |