Search code examples
javasshjschssh-keysopenssh

jsch auth fail without private key


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);

Solution

  • 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.