I am using ganymed SSH2 java library to connect to a server using public key authentication.
I have created the public/private key pair and uploaded the public key (mykey.pub) to my server in the /.ssh2 directory. I have the private key on my machine locally.
Info on keys: 2048-bit dsa key pair (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). This java library only accepts private keys in openssh format.
You can see for yourself that the key isn’t in the expected format. How did you generate it?