# About
One use case for using remote port-forwarding is if a local machine is stuck behind a vpn or firewall and it needs to be accessed by a remote machine. Simple ssh will suffice but we use autossh to keep the connection reliably open for a long period of time.

#  Commands
### Allow SSH into first machine (local) from second (remote) and third (third party) machine
Open up ssh port on the first machine, such that it can be accessed by the second machine. We will use the first, second
and third to mean the same machines in all examples.

* The following command should be run on the first machine.
* Autossh requires two additional echo ports on the second machine. Autossh uses these two ports to check if the connection is alive or not. So in all, the second machine must open three ports in the firewall for autossh to work. For this example we use the following ports:
  * ACCESS_PORT = 8080
  * ECHO_PORT_1 = 20000
  * ECHO_PORT_2 = ECHO_PORT_1 + 1 (20001) (This is done automatically by autossh if not manually set).
* The command that needs to be run on the first machine is of the following form:
  ```bash
  # Usage
  $ autossh -M ECHO_PORT_1 -fNR IP-ON-SECOND:ACCESS_PORT:IP-ON-FIRST:SSH-PORT second-user@second-host
  
  # Example
  $ autossh -M 20000 -fNR 0.0.0.0:8080:localhost:22 second-user@second-host
  ```
* The command that needs to be run on the second machine to access the first machine via ssh is of the following form:
  ```bash
  # Usage
  $ ssh first-user@second-host -p ACCESS_PORT
  
  # Example
  $ ssh first-user@locahost -p 8080
  ### OR 
  $ ssh first-user@0.0.0.0 -p 8080
  ```
* The command that needs to be run by a third machine trying to gain access to the first machine via the second machine is of the following form:
  ```bash
  # Usage
  $ ssh first-user@second-host -p ACCESS_PORT
  
  # Example
  $ ssh first-user@second-host -p 8080
  ```