Linux – Making a multi hop SSH tunnel a thesql server (3-4 hops)

linuxmac-osxMySQLsshtunneling

I'm trying to get to a mysql server on a remote network, and to get to it I currently have to do several ssh hops, so I can use the mysql command line interface. I'd really like to do a mulit-hop tunnel so I can just use a gui from my desktop. How would this work?

Here's the order:

MacDesktop –> DevServer –>StageServer –> Mysql01

All (except the mac desktop)are linux boxes, and mysql is running on the standard port.
Any Hints? Or an exact connection string?

Best Answer

You can use ssh to forward the ports(assuming that the mysql server is configured to accept connections from StageServer on port 3306):

# Forward port 3306 from Mysql01 to local port 3306 on DevServer using StageServer in the middle
DevServer > ssh -L 3306:Mysql01:3306 StageServer
# Forward the local port 3306 on DevServer to local port 3306 on your Mac
MacDesktop> ssh -L 3306:127.0.0.1:3306 DevServer

Now configure the gui client to connect to 127.0.0.1:3306 (Make sure you're not running mysql on your Mac or forwarding to port 3306 will fail, or use another port for forwarding)

Edit: Make sure that local port forwarding is enabled in ssh server configuration.