【发布时间】:2020-03-25 19:51:11
【问题描述】:
我正在尝试通过 JGit 使用 JSch 版本 0.1.55 对远程 Git 服务器进行身份验证。使用命令行 Git 身份验证工作正常,但通过 JSch,它就不行了。我得到的错误是:
Caused by: org.eclipse.jgit.errors.TransportException: git@REDACTED_HOST:petter/rio.git: Auth fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:158)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:107)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:306)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:143)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:127)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1335)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:137)
... 10 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:112)
... 16 more
我的理论是,根据调试日志的最后几行,它无法找到任何公钥:
11:07:56.228 [main] DEBUG re.dacted - JSCH: Authentications that can continue: publickey,keyboard-interactive,password
11:07:56.228 [main] DEBUG re.dacted - JSCH: Next authentication method: publickey
11:07:56.295 [main] DEBUG re.dacted - JSCH: Disconnecting from REDACTED_HOST port 22
我认为这可能是由 JSch 和我的 Mac 上的 ssh-agent 之间的一些奇怪的交互引起的(我正在使用 gpg-agent)。基于https://gist.github.com/niclasnilsson/038f20bee1bd19e970d59ba35732e262,我尝试创建一个.ssh/config 文件,其中包含'*' 条目,并且在某一时刻,我从UserAuthPublic 密钥类中得到了一个不同的错误。然而,无论我怎么努力,我似乎都无法回到那个阶段。
我还尝试了来自 https://dzone.com/articles/how-to-authenticate-with-jgit 的说明(ofc,没有硬编码密码,这似乎是一件非常奇怪的事情),但没有运气。似乎它甚至没有达到尝试调用 UserInfo 上的任何方法的地步。
我确实从ssh-add -l 得到了钥匙。不知道还能做什么才能尝试解决此问题。任何指针将不胜感激!
【问题讨论】:
标签: java git ssh jsch ssh-agent