USERAUTH失败,Github和Spring云配置的私钥文件

mCs*_*mCs 6 github spring-boot spring-cloud spring-cloud-config

我试图使用使用私钥的方法(具有密码短语,并且已从文件添加到ssh-agent中)(根据堆栈文章):

spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com-forApp:myorg/myrepo.git
          search-paths: '{application}'
          clone-on-start: true
          private_key_file: ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

但我不断

org.eclipse.jgit.api.errors.TransportException:git@github.com:myorg / myrepo.git:USERAUTH失败

将密钥粘贴到配置文件中时,我是否必须完全按照doc所述进行操作,还是可以以某种方式仅指向密钥文件?

编辑

实际上,事实证明private_key_file根本不需要或Spring忽略了。但是您需要使用~/.ssh/config指向私钥的部分:

Host github.com-forApp # used in spring uri 
       HostName github.com
       User git
       IdentityFile ~/.ssh/gitHubKey
Run Code Online (Sandbox Code Playgroud)

Imr*_*ran 6

我能够复制您的行为并通过以下方式解决它。让我知道你的想法。

USERAUTH fail发生这种情况是因为您没有提供 RSA 私钥的密码。(password对于基本身份验证和passphrasessh 私钥)

spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:myorg/myrepo.git
          search-paths: '{application}'
          clone-on-start: true
          passphrase: myprivatekeypassword
Run Code Online (Sandbox Code Playgroud)

默认情况下~/.ssh/id_rsa在 GIT SSH 身份验证期间发送(使用命令测试ssh -vT git@github.com。您不需要在配置中指定它。另外,我不确定是否private_key_file有效,因为我没有看到任何官方文档。

如果您有不同的命名 RSA 文件,.ssh那么我建议在~/.ssh/configgithub 主机详细信息和标识文件下创建配置文件。

这是一个例子。

Host github.com
    IdentityFile ~/.ssh/mygitid_rsa
Run Code Online (Sandbox Code Playgroud)

检查堆栈答案以获取更多详细信息,这些详细信息需要在配置中提供私钥文件路径的配置。