【问题标题】:USERAUTH fail with private key file for Github and Spring cloud configUSERAUTH 因 Github 和 Spring 云配置的私钥文件而失败
【发布时间】:2019-09-23 05:42:05
【问题描述】:

我尝试使用使用私钥的方法(具有密码并从文件添加到 ssh-agent)(根据this stack post):

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

但我不断得到

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

我是否必须像doc says 那样将密钥粘贴到配置文件中,还是只能以某种方式指向密钥文件?

编辑

实际上,private_key_file 根本不需要或被 Spring 忽略。但是你需要 ~/.ssh/config 部分指向私钥才能使用:

Host github.com-forApp # used in spring uri 
       HostName github.com
       User git
       IdentityFile ~/.ssh/gitHubKey

【问题讨论】:

  • 你配置你的 github 来接受你的 ssh 密钥了吗?
  • @BurakAkyıldız 是的,例如,当我使用 git 时,它使用我的 ssh 密钥,无需登录/密码

标签: spring-boot github spring-cloud spring-cloud-config


【解决方案1】:

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

USERAUTH fail 发生是因为您没有提供 RSA 私钥的密码。(password 用于基本身份验证,passphrase 用于 ssh 私钥)

spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:myorg/myrepo.git
          search-paths: '{application}'
          clone-on-start: true
          passphrase: myprivatekeypassword

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

如果您在 .ssh 下有不同的命名 RSA 文件,那么我建议您在 ~/.ssh/config 下创建配置文件,其中包含 github 主机详细信息并识别文件。

这是一个例子。

Host github.com
    IdentityFile ~/.ssh/mygitid_rsa

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

【讨论】:

  • 这完全是关于添加 passphrase ,即使使用 private_key_file 也不起作用,它也出现在您链接的答案中。无论是否添加到ssh-agent,它都有效。只有在将更改添加到配置仓库时,它才会要求输入密码
  • @mCs 正确。将它添加到 ssh-agent 并不重要,因为底层的 JGit 库没有引用它。
  • 实际上,private_key_file 根本不需要或被 Spring 忽略。但是您需要指向私钥的~/.ssh/config 部分才能在我的问题中使用
  • @mCs 是的。我分享的堆栈答案也是想要该功能,但尚不支持!。
猜你喜欢
  • 2020-03-25
  • 2019-07-18
  • 2021-11-09
  • 1970-01-01
  • 2016-01-20
  • 1970-01-01
  • 2019-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多