I would like to connect to a remote MySQL from my host, but the host is behind a ssh proxy, like this.
I have 3 hosts in this problem
- A: my local machine (that can ssh to B)
- B: Intermediate machine that can SSH to C
- C: a remote server running MySQL and allows only connections from localhost (grant)
I use ~/.ssh/config to allow me to ssh directly from A to C (using B as proxy).
Host B
ProtocolKeepAlives 30
HostName hostnameofB
Host C
ProtocolKeepAlives 30
ProxyCommand ssh -q B nc -q0 hostnameofC 22
LocalForward 3336 localhost:3306
Port 21343
I open a ssh from A to C with -vvv and see this:
debug1: Local connections to LOCALHOST:3336 forwarded to remote address localhost:3306
I then try to login to MySQL from A:
mysql -uMyUsername -pMyPassword DatabaseName -P3336 -h127.0.0.1
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
(if I try to use -hlocalhost it will try to log in to my local MySQL server, even if I use different ports)
in my SSH -vvv window I also see this:
client-session (t4 r0 i0/0 o0/0 fd 7/8 cc -1)
there is no logs on the C MySQL server.
any good suggestions?
Looks to me like your mysql command run on host A attempts to connect to port 3366 on A; I don't see anything forwarding A:3366 anywhere. Try adding a forwarding rule from A to B, or if there is no filtering done you can simply change your mysql commend to hit host B rather than "-h127.0.0.1" which refers to A.