How to bestly setup a ssh tunnel for access to a remote network (Linux)

My situation: I want to remotely debug my c++ application with gdbserver and eclipse. Eclipse is running on my local workstation (in the 192.168.0.0 network) and gdbserver is running on a clustermachine in the 10.0.0.0 network. I have ssh access to the clustermachine via a machine that is in both networks.

How can I set up a tunnel so that my eclipse can access the gdbserver? I don't have administrator rights/root/sudo access.

All the machines are linux/Unix with openssh.


Solution 1:

I trust you can already SSH to a system on the remote private network (10.0.0.0). If your local system is running openssh, add to your $HOME/.ssh/config:

Host gatewaymachine
  LocalForward 12080 remote_ip:portnum

Where 'remote_ip' is the IP address of the remote clustermachine system where gdbserver runs, and portnum is the port that it listens on. SSH to gatewaymachine, then connect your application to localhost, port 12080. For example if this is a web application

http://localhost:12080

If you're not using a web application, you'll need to set up your connection information to reflect that you're going to 'localhost' port '12080' (or whatever port you like, see below).

Instead of editing your ssh config, you can also use ssh command parameters:

ssh -L 12080:remote_ip:portnum gatewaymachine

(change 12080 to whatever port you want above 1024; below 1024 and you'll need root access to bind to the port)

Solution 2:

Basically, what jtimberman said :). You might want to look into autossh if you have trouble keeping your tunnel up for extended periods of time.