我使用Jsch和expectit连接到网络设备和更新CONFIGS,更改密码等..如何强制未闭合Jsch SSH连接关闭
我有哪里回环连接保持开放的一个问题,阻止创建更多的ssh会话。我读过这是某些版本的OpenSSH的问题,解决方案是升级sshd。不幸的是,当连接到网络设备时,这有时不是一种选择。
有没有解决方法?
编辑 - 这是我的代码 - 是不是我手动关闭所有东西?
JSch jSch = new JSch();
Session session = jSch.getSession("username", h.hostname);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword("password");
session.connect();
Channel channel = session.openChannel("shell");
Expect expect = new ExpectBuilder()
.withOutput(channel.getOutputStream())
.withInputs(channel.getInputStream(), channel.getExtInputStream())
.withEchoOutput(System.out)
.withEchoInput(System.err)
.withExceptionOnFailure()
.build();
channel.connect();
expect.expect(contains("#"));
expect.sendLine("showRules\r");
String response = expect.expect(regexp("#")).getBefore();
System.out.println("---" + response + "----");
expect.sendLine("exit\r");
expect.close();
channel.disconnect();
session.disconnect();
你所指的问题不会与我发出任何响铃。也许你可以向我们展示一些有问题的代码并解释问题所在。 – Kenster
在您编辑的代码中,当您完成所有代码时,您似乎正在关闭所有内容。什么是实际问题?你有什么不好的行为? – Kenster
经过约180次连接之后,我开始出现IOException异常:“无法建立环回连接”。当我执行netstat -na时,在TIME_WAIT状态下127.0.0.1上有100个连接。在这些关闭之前,我无法建立更多的ssh连接。 –