1

I have an mysql Server on hostD. I can access hostD through hostC, hostC through hostB, hostB through hostA and I access hostA using putty on my home device

home(windows)-->hostA-->hostB-->hostC--hostD(mySQL Server)

My goal is to access the server from my home device.

Another challenge is that I don't have any root access on A,B and C. Now I've been experimenting with the '.ssh/config' file and this is what I got so far:

 Host BTunnel
  HostName hostB
  LocalForward 3306 localhost:3306

 Host CTunnel
  HostName hostC
  LocalForward 3306 localhost:3306

 Host DTunnel
  HostName hostD
  LocalForward 3306 localhost:3306

This way I can connect from Putty--> hostA and type in consecutively:

ssh BTunnel
ssh CTunnel
ssh DTunnel

To get a tunnel from A to D. But I would like to have a solution, where I only type in 1 command from host A to get a Tunnel to D, maybe by chaining up the existing host aliases.

Can anyone offer a solution?

Anh Tuan
  • 11
  • 1
  • 2

1 Answers1

1

Well, you can just chaining the commands. You can do this even without any config files. Execute at hostA:

ssh -L 3306:localhost:3306 hostB ssh -L 3306:localhost:3306 hostC ssh -NL 3306:localhost:3306 hostD

If you have configs and public keys in place, you can do:

ssh BTunnel ssh CTunnel ssh -N DTunnel

(I would include the -N at the last command because I don't need shell access, just the forwarding.) You can make an alias for it in .bashrc (or similar):

alias mytunnel="ssh BTunnel ssh CTunnel ssh -N DTunnel"

you can start with mytunnel now.

goteguru
  • 191
  • 1
  • 8