简体   繁体   中英

Tunnel connection to Mysql without SSH access

From my local machine, I have SSH access to server A. Once on Server A, I connect to mysql on server B via port 3306 on server B.

mysql -h <B.hostname>  -P 3306 -u <username> -p

I do NOT have ssh access to server B, either from my local machine or from server A.

What I'd like to do is have access to mysql on server B from my local machine. Every tunneling/port-forwarding link I've found assumes that I can ssh into server B.

ssh's -L takes a local port, a remote hostname to connect from the ssh server you connect to, and the remote port. In this case, you'll run:

ssh -L 3307:B.hostname:3306 A.hostname

This will make ssh connect to A, and when you later connect to port 3307 using a local mysql client ( mysql -H localhost -P 3307 -u ... ), A's sshd will initiate a connection to B.hostname:3306 for you.

Sounds like you have to use remote port forwarding. Try this on your local host:

[auto]ssh -R 1111:127.0.0.1:2222 -f -N -4Cp1234 username@servername.net

So you get on your localhost:2222 (local machine) everything you get on localhost:1111 (when you logged in on servername.net), with traffic going by SSH on servername.net:1234 .

If your "server A" could access "server B" somehow, and you could access "server A" via SSH, that could probably help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM