How to create a SSH Tunnel

Today, I wanted to debug an application, which is not running on my local machine. My first shoot was to change the host in the configuration for remote debugging. Of course, the port was blocked and I got the following error message:

Error Running 'Remote debug':
Unable to open debugger port (remote-host:8000): "Connection reset"

That’s the point where the SSH tunnel comes into play. It’s possible to achieve the goal due to port forwarding. Of course, it’s a prerequisite that you have access to the remote server via SSH.

SSH has a -L option. This option listens to the defined port and forwards it to the remote machine. So in my case, if I start a debug session, the request will be forwarded to the remote machine. The command pattern looks like this:

ssh username@remote-host -L port:host:hostport

Let’s try it with my example case. Establish an SSH connection with the following command:

ssh zygann@remote-host -L 8000:localhost:8000

The first port defines my localhost port, which should be forwarded, followed by a colon. Then the host and the host port needs to be specified also separated by a colon.

That’s it. It’s quite easy, isn’t it? Now I’m able to debug the application on the remote machine and figure out, why it behaves differently to my machine. Did you have also an issue, where SSH forwarding could help you? Write it in the comment 🙂


Leave a comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.