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格式)是之前使用的舊格式

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章