mysqlsshremote-accesstunneljumphost

Mysql-Client Jumphost from Local Client to Webserver to DB Server without DB Server SSH User


My scenario looks as follows:

I have a web server and a DB server. On the webserver I have an SSH user with which I can connect to the database via mysql-client. The mysql port is restricted to the IP address of the webserver and I don't have an SSH user on the DB server.

I thought that some kind of SSH tunnel should be possible here, but I couldn't wrap my head around it yet.

I would have imagined something along these lines:

Tunnel: 127.0.0.1:9999 -> Webserver.IP:9999 -> DBserver.IP:3306

Mysql-Client CMD: mysql -u db_user -h 127.0.0.1 -p -P 9999

If anyone can share an idea on if and how this can be implemented I would be very grateful.


Solution

  • I have found a solution that works for me..

    Establish connection and keep it open: ssh -L 9999:[DB-SERVER.IP]:3306 [SSH-USER]@[WEB-SERVER.IP]

    Connect to the local source port: mysql -h 127.0.0.1 -P 9999 -u [DB-USER] -p