28
votes

I need to access from a PHP script a database hosted on another machine which is accessible only via SSH using a bridge machine.

How can I setup a tunnel so that I can tunnel the connection from my machine to the database passing through the 'bridge' machine?

2

2 Answers

52
votes

It is actually quite simple. It is just a matter of a single command:

ssh -N -L localhost:3306:DATABASE_MACHINE:3306 BRIDGE_MACHINE_USER@BRIDGE_MACHINE
1
votes

You should use ssh -L option to do this

You can read this: http://www.revsys.com/writings/quicktips/ssh-tunnel.html