1

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?

Oliver
  • 5,973
  • 24
  • 33
Sverre
  • 753
  • 2
  • 12
  • 23

1 Answers1

0

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.

Ram
  • 612
  • 3
  • 10
  • I though the line: LocalForward 3336 localhost:3306 did this for me, I did some more testing, and tried to do what I wanted to do, with only one jumb (A to B), host B hostName hostnameofB LocalForward 3336 localhost:3306 then I open a SSH to B, and run this SQL mysql -umyusername -pmypassword mydatabasename -hlocalhost --protocol=TCP -P3336 and this works fine. – Sverre Jul 12 '12 at 03:55
  • I also tried to setup intermediate forwarding on B, with LocalForward 3333 localhost:3336 on B, and LocalForward 3336 localhost:3306 on C but that also did not work. – Sverre Jul 12 '12 at 03:59
  • what is the -q0 in the proxycommand 'nc' call? – Ram Jul 12 '12 at 19:13