ssh git代码报错 Caused by: org.eclipse.jgit.errors.TransportException: git@gitlab invalid privatekey

 用ssh git代码的时候发现出现 invalid privatekey:的问题

Caused by: org.eclipse.jgit.errors.TransportException: [email protected]:xxx.git: invalid privatekey: [B@2fc74d70
        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$SshFetchConnection.<init>(TransportGitSsh.java:247)
        at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:137)
        at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:105)
        at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:91)
        at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1260)
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:211)
        ... 60 common frames omitted
Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@2fc74d70
        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:406)
        at com.dmall.autotestcenter.service.impl.GitServiceImpl$1.createDefaultJSch(GitServiceImpl.java:81)
        at org.eclipse.jgit.transport.JschConfigSessionFactory.getJSch(JschConfigSessionFactory.java:350)
        at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:308)
        at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:175)
        at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:105)
        ... 67 common frames omitted

原因是生成密钥的时候使用openssh版本生成导致版本过高:

解决办法:

ssh-keygen -m PEM -t rsa 重新生成旧格式的key,变可解决

-m 参数指定密钥的格式,PEM(也就是RSA格式)是之前使用的旧格式

猜你喜欢

转载自blog.csdn.net/qq_23948283/article/details/106335577