I recently needed to access a resource that was only available from a remote Linux PC (i.e. my machine → remote Linux PC → network resource). The problem? There’s no GUI, no X Server I only have SSH access. The solution? One option is to set up a local port forward (ssh -L local_socket:host:host_socket), but this is limited to only a single end point and won’t work if the remote network resource redirects traffic to another port. This would work if we are, for example, talking to a web server over HTTP (port 80), but we would need to create a separate rule for HTTPS (port 443) and any other port required (e.g. for web sockets).

Fortunately, another solution exists whereby I can use the remote Linux PC as a proxy server, essentially letting me work as if I was on the remote Linux PC instead of my machine. This solution involves using the SSH tunnel to the remote Linux PC as a local dynamic application-level port forward and treating the connection as a proxy. This can be activated from terminal using:

ssh -D 8080 -C2qTnN username@remote_linux_pc_address

This command will connect to remote_linux_pc_address using username and configure SSH as follows:

  • -D 8080 establishes a local port listener at port 8080 that you can attach a browser to use it as a SOCKS 5 proxy.
  • -C enable compressions.
  • -2 uses SSH version 2 only.
  • -q supresses warnings and diagnostic messages.
  • -T disables pseudo-terminal (tty) allocation.
  • -n redirects stdin to /dev/null, thus prevening reading of stdin.
  • -N tells SSH not to execute a remote command.

Next, set up a web browser to use a SOCKS 5 proxy with hostname localhost (or 127.0.0.1) and port 8080.

Note: If the web browser doesn’t respond, it’s possible the SSH connection has dropped.

Next Post