What are the exact differences between jsch ChannelExec and ChannelShell?

Can someone tell me the difference between ChannelExec and ChannelShell ?

+8
java ssh jsch
source share
3 answers

The shell and exec channels are quite similar - both commands execute with the remote shell (at least conceptually - the server, of course, can be configured to handle them differently). RFC 4254 groups them in the Interactive Sessions section , and both of them (as well as the subsystem, see below) use the session channel type in the SSH protocol.

There is one important difference:

  • For ChannelShell input stream provides commands and input for these commands. This is similar to using an interactive shell on your local computer. (And this is usually only used for this: interactive use.)

  • For ChannelExec commands are passed using setCommand () before connect() , and the input will be redirected to these commands as input. (Most often you will only have one command, but you can provide several commands using the usual shell separators & , && , | , || , ; , newline and compound commands.) This is similar to running a shell script on your local system. a computer. (Of course, if one of the commands is an interactive shell, it will behave like ChannelShell .)

  • There is a third analogue, ChannelSubsystem , which runs the ssh server subsystem - here the server configuration decides what to do, not the shell of the remote user. (The most commonly used subsystem is sftp , but for this, JSch provides a dedicated channel that understands the protocol.)

Please note that what I call “input stream” here is the data stream in the channel from the local to the remote host, which can actually be done by passing the Java InputStream to the setInputStream method or by getting the Java OutputStream from the getOutputStream method and writing to it .

+16
source share

There is another important difference between the exec channel and the shell channel: the shell channel will set the shell environment, such as environment variables, while the exec channel will not.

+1
source share

The Exec channel only supports Kch commands, for example, ls -l . If you try to run a shell job, it will ksh: run_pass: not found error like ksh: run_pass: not found

-one
source share

All Articles