Table of Contents

SSH - Left Tunnel (Left Port Forwarding) - Local to server

About

When you need to make a SSH connection to connect to a server, you can create a left tunnel (a left port forwarding) to reach the server as of it was direct reachable.

Illustration: Image Credit: How does reverse SSH tunneling work? from Erik

Ssh Tunnel Reach Server Through Ssh Remote Server

Usage

Steps

Create the tunnel

You can create the tunnel with any client such as:

Ssh

Create the tunnel: From the client host:

ssh -N -T -l loginName -L8881:farAwayServer:8888 sshServerHost

where

Jsch

Jsch is a java library.

JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
localPort = 4321;
remoteHost = "localhost";
remotePort = 3306;
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
session.connect();
int assigned_port = session.setPortForwardingL(localPort, remoteHost, remotePort);