Basically, I have a java program that controls two different SSH connections using the JSch SSH library for Java.
I create my own class called SSHConnection that is a wrapper for the JSch libraries, and I initialize two copies by calling the constructor shown below:
public SSHConnection(String username,String password,String host, String knownHosts, int portNumber) throws JSchException{
JSch jsch = new JSch(); jsch.setKnownHosts(knownHosts); this.session = jsch.getSession(username,host,portNumber); this.session.setPassword(password); this.session.connect();}
Now, inside the SSHConnection class, in order to create the shell channel, I use this command:
shell = (ChannelShell)this.session.openChannel("shell");
However, I have found out that if I have already have a session open that is using the SHELL channel I get an error saying "Channel is not opened" (JSch Exception) when I try to open the first channel for the second session.
Is there a way that I can open two Shell channels at once? Is this my problem, a JSch problem, or an SSH issue?
Edit::::
I can connect to the SSH server simultaneously from multiple terminals. For instance, in one terminal I can do...
ssh asofjpasf@myserver
and in another terminal I can do... ssh opapaos@myserver
However, when I try to make a single program using JSch have the same behavior, it fails stating that the channel is not open when I try to open the second shell channel.