Monday, January 27, 2014

Confusion Between Target Host and Local Host in SSH Tunnel


I was trying to tunnel VNC connections over SSH and I encountered a problem caused by a mistake I always make, setting up the SSH tunnel on the host that's going to VNC-view the target host:

$ ssh -f user@target_host -L 5905:target_host:5901 -N

I try to connect via this tunnel and I see:

channel 2: open failed: connect failed: Connection refused

I should have created the tunnel like this:

$ ssh -f user@target_host -L 5905:127.0.0.1:5901 -N

Then, VNC-ing to port 5905 on 127.0.0.1 works.