Assumptions:
- You have a remote machine configured to listen for VNC connections on such as :5900.
- You can ssh into your remote machine.
- You (wisely) have not opened port 5900 in your firewall.
- You want to access your machine remotely over VNC.
Let’s tunnel.
Rationale
VNC is basically plain text, including any keystrokes you send. Authentication is weak compared to such as ssh. And to access VNC remotely you’d ostensibly have to open that port to the Internet.
With ssh tunneling, you don’t have to open a special port in your firewall for VNC. All authentication and subsequent traffic happens over ssh.
Set up the tunnel
Try this:
ssh -C user@myhost.com -L 5900:127.0.0.1:5900
Feel free to add -fNq to background ssh (so you can’t accidentally close a terminal window and lose it), -N so that it doesn’t run any commands, and -q so that it’s quiet.
This connects you to myhost.com, forwarding your local port (hence -L) 5900 to the remote port 5900.
Connect
Use your favorite VNC client, connecting to localhost, port 5900, and with whatever credentials you set up.
Anecdata: slow?
I’ve only tested this once or twice. It seems pretty slow! I can’t tell if it’s the quality of this connection or what. So maybe prepare yourself.