Hi, problems using sshj

1,235 views
Skip to first unread message

Catalin Bararu

unread,
Apr 27, 2015, 5:38:58 PM4/27/15
to sshj-...@googlegroups.com
Hi, i am trying to connect a ssh server using sshj and execute a command (the exec example). I don't know if i got it wrong or if it is something else
The code is the following :
Introd public static void main (String[] args) throws IOException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("192.168.89.129", 22);
try {
ssh.authPublickey(System.getProperty("administrator"));
Session session = ssh.startSession();
try {
Command cmd = session.exec("ping -c 1 google.com");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
ssh.close();
}
}uceţi aici codul...
The error i receive is the following :
Introduceţi aici codul...[main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle already registered as a JCE provider
Exception in thread "main" java.io.IOException: Could not load known_hosts
at net.schmizz.sshj.SSHClient.loadKnownHosts(SSHClient.java:565)
at ssh.ClientSSH.main(ClientSSH.java:14)




Catalin Bararu

unread,
Apr 28, 2015, 4:35:56 PM4/28/15
to sshj-...@googlegroups.com
Hello again, so i tried without loading known host but it disconnects with the following error.
[HOST_KEY_NOT_VERIFIABLE] Could not verify `ecdsa-sha2-nistp256` host key with fingerprint
 I can't figure it how to verify the keys.

Any help ?

Eder F. Freitas

unread,
Jan 16, 2018, 10:52:48 AM1/16/18
to sshj-users
How did you solved this? I've the same problem.

Jeroen van Erp

unread,
Jan 16, 2018, 11:07:57 AM1/16/18
to sshj-...@googlegroups.com
Can you check the github issue tracker and open a ticket there describing your setup, what you tried and what you're getting? 

--
You received this message because you are subscribed to the Google Groups "sshj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sshj-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eder F. Freitas

unread,
Jan 17, 2018, 5:45:12 AM1/17/18
to sshj-users
I identified the problem, in my case the target host didn't exist on known_hosts from my source machine, I had first to do a logon on target machine to my ssh connection works. Is there a way to update known_hosts without conect first at target machine?

I know that there is a similar way  like this https://serverfault.com/a/316100/268311. Does SSHJ it automatically?


Em terça-feira, 16 de janeiro de 2018 14:07:57 UTC-2, Jeroen van Erp escreveu:
Can you check the github issue tracker and open a ticket there describing your setup, what you tried and what you're getting? 
2018-01-16 16:52 GMT+01:00 Eder F. Freitas <jederf...@gmail.com>:
How did you solved this? I've the same problem.


Em terça-feira, 28 de abril de 2015 17:35:56 UTC-3, Catalin Bararu escreveu:
Hello again, so i tried without loading known host but it disconnects with the following error.
[HOST_KEY_NOT_VERIFIABLE] Could not verify `ecdsa-sha2-nistp256` host key with fingerprint
 I can't figure it how to verify the keys.

Any help ?

--
You received this message because you are subscribed to the Google Groups "sshj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sshj-users+...@googlegroups.com.

Krishnan Mahadevan

unread,
Jan 17, 2018, 10:29:04 PM1/17/18
to sshj-...@googlegroups.com

Maybe you can try out something like this:

 

public static void main(String[] args) throws IOException {
   
final SSHClient client = new SSHClient();
    client.addHostKeyVerifier(
new PromiscuousVerifier()); //Adds a fake host verifier that treats every host as a known one (i.e., its part of the ~/.ssh/known_hosts file )
    client.connect(
"hostname");
   
try {
        client.authPassword(
"username", "password");
       
final Session session = client.startSession();
       
try {
           
final Session.Command cmd = session.exec("true");
            cmd.join(
1, TimeUnit.SECONDS);
        }
finally {
            session.close();
        }
    }
finally {
        client.disconnect();
    }
}

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages