SSH Forwarding

SSH in one of the most used command when server-client model is involved. There are two ways one can communicate SSH with local system.

  1. Local Forwarding

  2. Remote Forwarding

Local Forwarding

Local forwarding, also known as local port forwarding, allows you to forward a local port on your machine to a port on a remote machine through an SSH server. This is useful when you want to access services running on a remote machine securely, as if they were running locally.

Example: Let's say you have a remote server with a web application running on port 8080. You want to access this web application securely from your local machine. You can use local forwarding as follows:

ssh -L 8080:localhost:8080 username@remote_server
  • L 8080:localhost:8080 specifies local port forwarding. It forwards connections from port 8080 on your local machine to port 8080 on the remote server.

After establishing the SSH connection, you can access the web application by navigating to http://localhost:8080 in your local web browser.

Remote Forwarding

Remote forwarding, also known as remote port forwarding, allows you to forward a port on a remote machine to a port on your local machine through an SSH server. This is useful when you want to expose a service running on your local machine to the outside world securely.

Example: Let's say you have a local web server running on port 3000, and you want to make it accessible from a remote server. You can use remote forwarding as follows:

ssh -R 8888:localhost:3000 username@remote_server
  • R 8888:localhost:3000 specifies remote port forwarding. It forwards connections from port 8888 on the remote server to port 3000 on your local machine.

After establishing the SSH connection, anyone who has access to the remote server can access your local web server by navigating to http://localhost:8888 from their browser.

In both cases, SSH encrypts the forwarded connections, providing a secure way to access services across networks.