I am currently running a Java Mina SSHD server.
I had my server running fine with sshd-core-0.14.0
but my virus scanner was flagging weak ciphers leaving me no choice but to upgrade to version 2.5.1
. I have tried simply replacing the .jar files and changing the classpath
vars to the new versions but get the following error.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.sshd.commo
n.KeyPairProvider
at java.lang.J9VMInternals.prepareClassImpl(Native Method)
at java.lang.J9VMInternals.prepare(J9VMInternals.java:303)
at java.lang.Class.getMethodHelper(Class.java:1247)
at java.lang.Class.getMethod(Class.java:1191)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:556
)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:538)
Caused by: java.lang.ClassNotFoundException: org.apache.sshd.common.KeyPairProvi
der
at java.net.URLClassLoader.findClass(URLClassLoader.java:610)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:944)
at java.lang.ClassLoader.loadClass(ClassLoader.java:889)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:872)
... 6 more
The code that starts my java based SSHD is here:
import org.apache.sshd.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WinSSHServer {
public WinSSHServer(Properties props) throws IOException {
final SshServer sshd = SshServer.setUpDefaultServer();
sshd.getProperties().put(SshServer.IDLE_TIMEOUT, String.valueOf(sessionTimeoutMSec));
sshd.setPort(22);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(props.getProperty("hostkey")));
sshd.setCommandFactory(new WinCmdExeCommandFactory());
final PuTTYPublicKeyAuthenticator pka = new PuTTYPublicKeyAuthenticator();
addPublicKeysFromProps(pka, props);
sshd.setPublickeyAuthenticator(pka);
sshd.start();
}
I searched in a maven repository index site and found a JAR that contains the same class. However, there is a change in the path that you likely have to configure on your end.
I did this using a zip utility (7zip) to search through the packages to find the class name in question and its fully-qualified class path. There are other ways to do this as well.
https://mvnrepository.com/artifact/org.apache.sshd/sshd-common/2.5.1
The path given in the exception stack by original poster is org.apache.sshd.common.KeyPairProvider however in this package it appears to be org.apache.sshd.common.keyprovider.KeyPairProvider (note the keyprovider that was added).
Steps to troubleshoot: