使用JSch时“无效私钥”

使用JSch时“无效私钥”,第1张

使用JSch时“无效私钥”

我也偶然发现了这个问题。在 mac* 上运行 Jgit ,对于某些用户,我们看到了以下异常: *

org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:160)    at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)    at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:274)    at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:169)    at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)    at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)    at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1236)    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:234)    ... 17 moreCaused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@e4487af    at com.jcraft.jsch.KeyPair.load(KeyPair.java:664)    at com.jcraft.jsch.KeyPair.load(KeyPair.java:561)    at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)    at com.jcraft.jsch.JSch.addIdentity(JSch.java:407)    at com.jcraft.jsch.JSch.addIdentity(JSch.java:367)    at org.eclipse.jgit.transport.JschConfigSessionFactory.getJSch(JschConfigSessionFactory.java:276)    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:220)    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:176)    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:110)

发现根本原因是ssh私钥不匹配。仅对于使用较新类型 ed25519的 密钥的用户才发生此异常,该用户输出以下密钥头:

-----BEGIN OPENSSH PRIVATE KEY-----

而不是 RSA

-----BEGIN RSA PRIVATE KEY-----

重新生成RSA密钥(

ssh-keygen -t rsa
),该异常消失了。

编辑以下注释:如果您具有OpenSSH 7.8及更高版本,则可能需要在生成命令中添加-m PEM:

ssh-keygen -t rsa -m PEM



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5175823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存