简体   繁体   English

ganymed SSH2 Java

[英]ganymed SSH2 java

I am using ganymed SSH2 java library to connect to a server using public key authentication. 我正在使用ganymed SSH2 Java库使用公共密钥身份验证连接到服务器。 I have created the public/private key pair and uploaded the public key (mykey.pub) to my server in the /.ssh2 directory. 我已经创建了公用/专用密钥对,并将公用密钥(mykey.pub)上传到我的服务器在/.ssh2目录中。 I have the private key on my machine locally. 我在本地计算机上拥有私钥。

Info on keys: 2048-bit dsa key pair (ssh2) 密钥信息:2048位dsa密钥对(ssh2)

I am doing something like this: 我正在做这样的事情:

File keyfile = new File("C:\\keys\\mykey");                  
String keyfilePass = "a"; // will be ignored if not needed

        try
        {

            Connection conn = new Connection(hostname);
            conn.connect();


            boolean isAuthenticated = conn.authenticateWithPublicKey("myusername", keyfile, keyfilePass); 
           //I get an error at this line

The error I am getting is: 我得到的错误是:

Caused by: java.io.IOException: Invalid PEM structure, '-----BEGIN...' missing
    at ch.ethz.ssh2.crypto.PEMDecoder.parsePEM(PEMDecoder.java:138)

Can anyone help? 有人可以帮忙吗? Is there any other library that works better than this? 还有其他比这更好的库吗?

EDIT: Key FILE 编辑:密钥文件

---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----
Subject: username    Comment: "2048-bit dsa, username@host, Tue Jul 31 2012 13:12:48 -\
0500"
KEY   
---- END SSH2 ENCRYPTED PRIVATE KEY ----

SOLUTION: 解:

I figured the problem out, the key had to be converted to OPENSSH format (I used puttygen for that). 我发现问题所在,密钥必须转换为OPENSSH格式(为此我使用了puttygen)。 This java library only accepts private keys in openssh format. 该Java库仅接受openssh格式的私钥。

The header "BEGIN SSH2 ENCRYPTED PRIVATE KEY" means that your private key has been generated by the proprietary ssh system from ssh.com. 标头“ BEGIN SSH2加密的私钥”表示您的私钥是由ssh.com的专有ssh系统生成的。

Is there any other library that works better than this? 还有其他比这更好的库吗?

JSch will accept it if your key is not ciphered. 如果您的密钥未加密,JSch将接受它。

You can see for yourself that the key isn't in the expected format. 您可以自己看到密钥不是预期的格式。 How did you generate it? 您是如何产生的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM