2022-09-07 22:24:18 -06:00
|
|
|
# SSH port forwarding
|
2022-10-12 17:15:13 -06:00
|
|
|
Local port forwarding allows ssh to connect one of your ports to the
|
|
|
|
destination's port. This is particularly useful for localhosted websites, which
|
|
|
|
you can run on the host and access on your machine
|
|
|
|
|
|
|
|
Some key terms:
|
|
|
|
```
|
|
|
|
<client-port> = Port on the machine you're using to ssh. Ex: laptop
|
|
|
|
<host-port> = Port on the machine running sshd
|
|
|
|
<host-address> = URL of machine running the sshd, which you're logging onto
|
|
|
|
<url-from-host> = Name relative to the host machine who's port the host forwards
|
|
|
|
```
|
|
|
|
|
|
|
|
The opens an ssh tunnel without obstructing the current terminal:
|
|
|
|
```bash
|
2022-10-17 12:42:16 -06:00
|
|
|
ssh -NL 8001:localhost:7000 emiliko@cs.ox.ac.uk &
|
2022-10-12 17:15:13 -06:00
|
|
|
ssh -NL <client-port>:<url-from-host>:<host-port> <user>@<host-address> &
|
|
|
|
```
|
|
|
|
|
|
|
|
# In config file
|
2022-10-17 12:42:16 -06:00
|
|
|
The syntax in the `~/.ssh/config` is quite similar
|
2022-10-12 17:15:13 -06:00
|
|
|
|
|
|
|
```ssh
|
2022-10-17 12:42:16 -06:00
|
|
|
Host mirrorside
|
|
|
|
User emiliko
|
|
|
|
Hostname cs.ox.ac.uk
|
2022-10-12 17:15:13 -06:00
|
|
|
LocalForward 8001 localhost:7000
|
2022-10-17 12:42:16 -06:00
|
|
|
```
|
|
|
|
|
|
|
|
The general format looks like
|
|
|
|
```ssh
|
2022-10-12 17:15:13 -06:00
|
|
|
LocalForward <client-port> <host-address>:<host-port>
|
|
|
|
```
|