You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Alexander Amador <al...@oracle.com> on 2022/08/10 15:41:08 UTC

How to add local port forwarding with Apache MIna sshd

Hi,

I am trying to implement an ssh tunnel in Apache Mina sshd  that resembles this command  "ssh -L 9000:localhost:8080 user@remoteHost "

So far I have come up with the following code .....

                  client = SshClient.setUpDefaultClient();
                  client.setKeyExchangeFactories(CopyLogSnapshot.setUpDefaultKeyExchanges(false));
                  client.start();

                  session = client.connect("root", host, 22).verify(500).getSession();
                  session.addPasswordIdentity("beer");
                  session.auth().verify(500, TimeUnit.SECONDS);

                  channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
                  channel.setIn(new NoCloseInputStream(System.in));
                  channel.setOut(new NoCloseOutputStream(System.out));
                  channel.setErr(new NoCloseOutputStream(System.err));
                  channel.open();

                  fwd = session.createLocalPortForwardingTracker(new SshdSocketAddress("0.0.0.0", 9000),
                              new SshdSocketAddress("0.0.0.0", 8080));

                  System.out.println("Connected to " + host);

                  // Create the keyboard-interactive instance
                  UserAuthKeyboardInteractive kbi = new UserAuthKeyboardInteractive();
                  kbi.init(session, "service");


I end up with a shell that is logged into my host, but when I test local port 9000 to remote host:8080 I am not getting my responses.
The shell keeps working during this time, responding with prompt and data.
I am using a browser to reach a simple webserver. I do initially receive some responses, the responses that return are delayed and then after 2 or 3 it stops responding.
I am looking for obvious set up errors that I have committed.
Any direction in regards to this will be greatly appreciated.

Thanks,
Alex Amador