0

I want use JSch as a common shell interactive tool, it's really useful.

I want create a ssh which is inner JSch channel shell and the shell's InputStream and OutStream is maintained by myself.

The problem is when I send a command string, ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o StrictHostKeyChecking=no -o ConnectTimeout=10 -T root@xxx.xxx.xxx.xxx -p 22, to OutputStream to setting a keep-live by ServerAliveInterval but it not works at all.the new channel will hold 1 min when I close network.This time is more over my config ServerAliveInterval=5 ServerAliveCountMax=2.

Is JSch support inner ssh connection setting to handle keep-alive check, such as ServerAliveInterval?

UPDATE

some step to describe the question:
1. create a shell channel use JSch to login host1
2. use the channel jump to host2 by send a command ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=2 root@xxx.xxx.xxx.xxx -p 22 which is a byte stream. The new ssh is config with ServerAliveInterval to check ssh network status of host2.

JSch can recognize host1 is disconnect if I'm use Session.setServerAliveInterval method and test it with Session.isConnected.
The problem is host2 can't be checked if only host2 network is break even through I'm use ServerAliveInterval config when jump to host2.It will hold a long time (more then 1min on my test) until get a packet_write_wait: Connection to xxx.xxx.xxx.xxx port 22: Broken pipe. But I'm expect some error message arrived less then 10 seconds as the ServerAliveInterval=5 ServerAliveCountMax=2 was set.

LoranceChen
  • 2,453
  • 2
  • 22
  • 48
  • Do I understand right, that you expect that sending `ssh -o ServerAliveInterval=5` to a shell session (created by JSch) affects the session itself? – Martin Prikryl Nov 05 '17 at 16:01
  • @MartinPrikryl yes, the problem is that the setting not has a affect inner jsch shell channel. – LoranceChen Nov 05 '17 at 17:02
  • Sorry, the problem seems my bug, I'm fixing. – LoranceChen Nov 06 '17 at 03:35
  • Sorry, but your question is so confusing. You do not have anything like *"inner jsch shell channel"*. + Anyway, if you manually login with a regular SSH terminal client and type your command on command-line, does it stay alive or not? – Martin Prikryl Nov 06 '17 at 06:45
  • @MartinPrikryl, It can stay alive.With some research, I find it's a difficult to transfer shell stream data to a normal function call in program(consider network fail etc).Using a shell channel jump to another host is also dangerous. – LoranceChen Nov 06 '17 at 07:49

1 Answers1

0

The shell is a black box for JSCh.

JSch is not aware of anything that you do there.

If you want to emulate, what OpenSSH ServerAliveInterval directive does, use Session.setServerAliveInterval.

See also JSch: How to keep the session alive and up.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • hi, I have attempt the config, but sorry, it not work. This set method only effect JSch's straight shell channel which it connect host but the sub ssh created inner the shell channel will not be check connection state.For detail, see my update above.Thanks – LoranceChen Nov 06 '17 at 00:08
  • Hi, sorry, the problem seems my bug, I'm fixing. – LoranceChen Nov 06 '17 at 03:34