SSH tunnel via gateway
To set up an SSH tunnel from here
to remote
via gateway
, as illustrated below:
+------+ +---------+ +--------+
| here | | gateway | | remote |
| 22:+-----+:22 | | |
|50000:----------------+-----+:22 |
| +-----+ | | |
| | | | | |
+------+ +---------+ +--------+
Run the following command on here
to create the SSH tunnel:
ssh -f -N -L 0.0.0.0:50000:remote:22 user@gateway
The command will return, but the tunnel will continue to run as a background process.
Afterwards, any connections to here:50000
will access remote:22
, for example:
[here ~]$ ssh user@here -p 50000
user@here's password:
Last login: Fri Jan 19 14:35:54 2018 from 192.168.57.23
[remote ~]$
See this answer for other tunnel configurations.