Linux 101 : SSH tunnels - Local and remote port forwarding -

SSH tunnels
allow us to forward local ports to remote machine, or forward remote ports to local machines, while creating encrypted connection between the client machines and the destination machines.

Local Port Forwarding:

Local Port Forwarding forwards a connection from the local host to the SSH server host, before forwarding it again to the destination host.

The local machine connects to the SSH server, while listening on the local port 5000.
When we connect to the local machine on port 5000, SSH will start a connection from the SSH server to the destination host on port 25.

Below is the command that achieves that:

Remote Port Forwarding:

Remote Port Forwarding
 forwards a port from the remote SSH server to the client, before forwarding it again to the to the destination machine.

Below is the command that achieves that:

Sets up an SSH connection with the SSH server, the SSH server is listening to connections on port 5000.
When we connect to port 5000 on the SSH server, SSH will open
a connection from the client to the port 25 of the destination host.


We could optionally mention the user on the SSH server using the below syntax "user@ssh_server".


Leave as a comment: