0

Although there are examples in sshj's github, I don’t understand what I’m doing. I use the following code to try to connect to my host, and that’s it

 @Test
    public void sshTest() throws IOException {
        SSHClient client = new SSHClient();
        String username = "username";
        File privateKey = new File("D:\\SSH\\remote_new");
        client.addHostKeyVerifier(new PromiscuousVerifier());
        client.connect("myMostIp", 22);
        KeyProvider keys = client.loadKeys(privateKey.getPath());
        client.authPublickey(username, keys);
        client.close();
    }

The result of running is like this

net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods


Caused by: net.schmizz.sshj.userauth.UserAuthException: Problem getting public key from PKCS8KeyFile{resource=[PrivateKeyFileResource] D:\SSH\matcloud_new}

    ... 66 more
Caused by: java.io.IOException: unrecognised object: OPENSSH PRIVATE KEY
    at org.bouncycastle.openssl.PEMParser.readObject(Unknown Source)
    ... 71 more

Format of the key file

-----BEGIN OPENSSH PRIVATE KEY-----
XXXXXXXXX
-----END OPENSSH PRIVATE KEY-----

I don't know what to do, jsch does not support key files in this format

Tablo_Jhin
  • 301
  • 1
  • 3
  • 10
  • What version of sshj? According to the README on github, sshj (which is different from jsch, even though both implement SSH) supports OpenSSH-newformat files for Ed25519 since 0.19.0 2016-11-25 and other keytypes since 0.27.0 2019-01-24 – dave_thompson_085 Dec 29 '20 at 11:17
  • I use the latest version 0.10.0, but the problem is that when I use sshj, I can’t even log in with a password. – Tablo_Jhin Dec 31 '20 at 02:27
  • 0.10.0 is not anywhere near the latest version, it is from 2014. If the host allows password auth (not all do) to use it you need to call one of the `.authPassword()` methods. – dave_thompson_085 Jan 03 '21 at 01:06
  • So what is the latest version? When using jsch, you can normally connect through password, but not through sshj. Jsch does not support the new version of openssh key format – Tablo_Jhin Jan 11 '21 at 03:16
  • [The most recent release is 0.30.0](https://github.com/hierynomus/sshj#user-content-release-history) although as I said before 0.27.0 (from 2 years ago) or higher should fully support OpenSSH-newfmt files. – dave_thompson_085 Jan 12 '21 at 06:40

1 Answers1

0

The most recent release is 0.30.0 although as I said before 0.27.0 (from 2 years ago) or higher should fully support OpenSSH-newfmt files. – dave_thompson_085

use it https://github.com/hierynomus/sshj#user-content-release-history

Tablo_Jhin
  • 301
  • 1
  • 3
  • 10
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 26 '22 at 08:09