2016-10-10 100 views
2

我在Linux(arch)上,尝试使用ssh密钥尝试配置此tutorial以及使用专用bitbucket git存储库配置Spring Cloud Config,但我不断收到错误:Spring Cloud Config无法使用ssh密钥克隆专用bitbucket存储库

现在
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. "[email protected]: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).

我有在的〜/ .ssh文件夹命名到位桶-RSA的私人SSH密钥,创建使用命令ssh-keygen -t rsa -b 4096 -C "[email protected]"。公钥已正确添加到Bitbucket中,因为我可以从命令行克隆,从存储库中拉出并推送,而不会出现问题。私钥已添加到ssh-agent中,bitbucket.org存在于known_hosts文件中。

下面是在配置服务项目bootstrap.yml:

spring: 
    application: 
    name: config-service 
    cloud: 
    config: 
     server: 
     git: 
      uri: "[email protected]:TarekSaid/my-private-repo.git" 
server: 
    port: 8888 

使用HTTPS使用用户名和密码的作品,但我还是喜欢使用SSH密钥,我怎样才能使它发挥作用?

回答

6

终于做到了!

这个问题:How to use a custom ssh key location with Spring Cloud Config指出我在正确的方向。我调试了JschConfigSessionFactory类,发现当没有提供用户名和密码时,它从~/.ssh/config的默认配置文件中获取配置。

因此,所有我必须做的是以下内容添加到我的的〜/ .ssh/config中文件:

的〜/ .ssh/config中

Host bitbucket.org 
    User TarekSaid 
    Hostname bitbucket.org 
    PreferredAuthentications publickey 
    IdentitiesOnly yes 
    IdentityFile ~/.ssh/bitbucket_rsa 

现在,它的工作。

相关问题