小编典典

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

spring-boot

我试图使用使用私钥的方法(具有密码短语,并且已从文件添加到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

但我不断

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

阅读 957

收藏
2020-05-30

共1个答案

小编典典

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

USERAUTH fail之所以发生这种情况,是因为您没有提供RSA私钥的密码。(password用于Basic
Auth和passphrasessh私钥)

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,由于没有任何官方文档,因此我不确定是否可行。

如果您在下面有另一个名为RSA的文件,.ssh那么我建议您在~/.ssh/configgithub主机详细信息下创建配置文件并标识该文件。

这是一个例子。

Host github.com
    IdentityFile ~/.ssh/mygitid_rsa
2020-05-30