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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top