我正在尝试使用 JSch Java 客户端通过 ssh 连接到服务器。我可以从我的命令行 ssh 它但是当我通过 JSch 库执行它时我收到了这个错误:
com.jcraft.jsch.JSchException: connection is closed by foreign host
同时使用 JSCH 连接到服务器。
java.util.Properties config = new java.util.Properties();
config.put("KexAlgorithms", "[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1");
config.put("kex", "[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1");
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(USERNAME, REMOTE_HOST, 53);
session.setPassword(PASSWORD);
session.setConfig(config);
session.connect();
System.out.println("Connected");
我做错了什么?