Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an SSH tunnel to accept incoming connections

There's something I'm trying to accomplish using SSH tunneling, but I tried googling "SSH tunneling" and found discussions about various different scenarios, but not my scenario.

I'm working on computer A. I have SSH access to computer B. I want computer B to run program X that needs to connect to port 40000 on computer A. Problem is, computer B has draconian firewalls applied to it that I don't want to modify. What I want is to leverage my ability to easily connect with SSH from computer A to computer B, to make the connection from B to A possible.

This is what I'm envisioning: A program Y that I run on computer A, which connects to computer B by SSH, and then listens, on computer B, to connections on port 40000, and forwards them through the SSH connections to port 40000 on computer A. Then I configure program X on computer B to try to connect to port 40000 on computer B, and then it's in effect connecting to port 40000 on computer A.

Is there an existing program / SSH recipe that does this?

like image 644
Ram Rachum Avatar asked Nov 10 '22 10:11

Ram Rachum


1 Answers

I guess you are looking for the -R option to ssh:

 -R [bind_address:]port:host:hostport
         Specifies that the given port on the remote (server) host is to be
         forwarded to the given host and port on the local side.  This works
         by allocating a socket to listen to port on the remote side, and
         whenever a connection is made to this port, the connection is for-
         warded over the secure channel, and a connection is made to host
         port hostport from the local machine.
         [...]
like image 58
mmjb Avatar answered Nov 15 '22 05:11

mmjb