Sometimes that we need to connect via SSH into another computer, we find out that this computer that we intend to SSH into (which we are going to call "destiny") may be utilizing NAT and therefore it doesn 't count with a public IP address that we could use to connect to it, or it may be behind a firewall that won' t allow access from the outside.
If "destiny" can successfully establish a SSH connection to another computer that is accessible, we can utilize this second computer to establish a reverse SSH tunnel to our "destiny" computer, we are going to call this second computer "origin" (even if it is not actually the computer that we are going to use to manage "target" remotely, but only a bridge).
A reverse SSH tunnel works by connecting "destiny" to "origin" and then utilizing this connection to SSH into "destiny" from any computer that is connected to "origin". This reverse SSH tunnel should work in most Linux systems without any problem.
So, lets assume that we have this two computers:
"Origin" IP: aaa.bbb.ccc.ddd
"Destiny" IP: unknown or unavailable
First of all, we establish the SSH connection from "destiny" to "origin", enabling the reverse SSH functionality with the parameter – a:
SSH r 61999:localhost:22 firstname.lastname@example.org
The first number (61999) indicates which port are we going to use in "origin" to log into "destiny", localhost is the domain name that we will be using for this as well, and the last number (22) indicates which port is "destiny" listening to for SSH.
Once this connection is live, and being logged in "origin" (it doesn't matter if we are logged in locally or remotely), we can establish the connection to "destiny":
SSH p 61999 destiny_user@localhost
Effectively, we can use a computer with permanent SSH access as a bridge between computers that are not otherwise accessible via SSH. Any computer that is connected to "origin" can log into other computers with reverse SSH tunneling enabled.