0

I'm using Jsch for executing ssh commands. When I pass private key it works well, but I need it to work without private key passing (it was already copied there).

So in console I can ssh to this server without anything. But Jsch throws Auth Fail. How can I do it ?

Session session = jSch.getSession(server);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("UserKnownHostsFile", "/dev/null");
session.connect(connectTimeout);

1 Answers1

1

By design, you always need to have the private key to prove you are who you say you are. Your private key is never "already copied there." If you are successfully connecting with ssh in a shell "without anything" it is certainly because your ssh is configured to find the private key and it is doing so successfully.

Rob
  • 6,247
  • 2
  • 25
  • 33
  • 1
    yes, for example I did ssh-copy-id before. In console I can ssh to this server. Jsch can't do it – Alexander alex Nov 18 '14 at 19:15
  • @Alexanderalex `ssh-copy-id` copies your public key to the server, not your private key. When you ssh in your shell, it certainly is accessing your private key (which is likely stored in ~/.ssh). – Rob Nov 18 '14 at 19:21
  • I also have config in .ssh. There is specified identity file. – Alexander alex Nov 18 '14 at 19:26
  • @Alexanderalex So is your question really "How do I get JSch to use my ssh config so that the private key will be found automatically?"? If so, you might look at [this example](http://www.jcraft.com/jsch/examples/OpenSSHConfig.java.html) – Rob Nov 18 '14 at 19:32
  • yes, thank you! But If there is ability to not pass the path to config ? I mean Jsch to use .ssh/config. – Alexander alex Nov 18 '14 at 19:43