There are multiple ways to configure SSH for port forwarding, and this post intends to serve as a handy cheatsheet that you can reference the next time you need this functionality.
When SSH is Already Established
If you already have an SSH connection up, you can insert SSH command mode by typing the following on a new line:
Then you can issue the following command to configure a local port forward.
For example, let’s say you’re connected to a machine via SSH and find that a webserver is running on port 52846, but only allows local connections. You can run the following command to forward port 9002 from your Kali machine through the SSH connection and access the webserver.
Now going to http://localhost:9002 will redirect through the tunnel and display the webpage that is listening on the remote system on port 52846.