Search code examples
javasshreversejschssh-tunnel

Reverse SSH tunnel with JSCH Java


Is it possible to do a reverse ssh connection using JSCH? If it is not, is there any other pure Java library that I can use to do a reverse tunnel SSH connection?

The command I want to mimic is similar than:

ssh -fN -R 7000:localhost:22 username@yourMachine-ipaddress


Solution

  • There is an example gist that shows how to do it here: https://gist.github.com/ymnk/2318108#file-portforwardingr-java

    The method you want to look at is session.setPortForwardingR()

    session.setPortForwardingR(rport, lhost, lport);