1
我有嘗試打開ssh連接下面的示例代碼不能使用JSch與JDK開放SSH會話8
package jsch;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
public class Main {
public static void main(String... args) {
JSch jsch=new JSch();
try {
Session session=jsch.getSession("some_user", "some_host", 22);
session.setPassword("some_password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Thread.sleep(1000);
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
如果我使用JDK 7中一切正常,但如果我使用JDK 8我m如果該堆棧跟蹤:
Exception in thread "main" java.lang.IllegalArgumentException: Empty nameStrings not allowed
at sun.security.krb5.PrincipalName.validateNameStrings(PrincipalName.java:167)
at sun.security.krb5.PrincipalName.<init>(PrincipalName.java:277)
at sun.security.krb5.PrincipalName.parse(PrincipalName.java:315)
at sun.security.krb5.internal.KRBError.init(KRBError.java:355)
at sun.security.krb5.internal.KRBError.<init>(KRBError.java:186)
at sun.security.krb5.KrbTgsRep.<init>(KrbTgsRep.java:58)
at sun.security.krb5.KrbTgsReq.getReply(KrbTgsReq.java:259)
at sun.security.krb5.KrbTgsReq.sendAndGetCreds(KrbTgsReq.java:270)
at sun.security.krb5.internal.CredentialsUtil.serviceCreds(CredentialsUtil.java:302)
at sun.security.krb5.internal.CredentialsUtil.acquireServiceCreds(CredentialsUtil.java:120)
at sun.security.krb5.Credentials.acquireServiceCreds(Credentials.java:458)
at sun.security.jgss.krb5.Krb5Context.initSecContext(Krb5Context.java:693)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:248)
at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)
at com.jcraft.jsch.jgss.GSSContextKrb5.init(GSSContextKrb5.java:129)
at com.jcraft.jsch.UserAuthGSSAPIWithMIC.start(UserAuthGSSAPIWithMIC.java:135)
at com.jcraft.jsch.Session.connect(Session.java:463)
at com.jcraft.jsch.Session.connect(Session.java:183)
at jsch.Main.main(Main.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
是否有機會解決這一問題,而不黑客和使用JSch與JDK8或者我應該切換到另一個SSH庫?