To make an ssh tunnel from client (VNC Viewer) to server, we will use

ssh -t -L 5900:localhost:5933 user@third-machine.net

Here, the command means: connect with ssh to user@third-machine.net, and forward all connection attempts to the local 5900 to port 5933 on the machine called localhost, which can be reached from the third-machine.net machine.

To make an ssh tunnel from host (VNC server) to server, we will use

ssh -t -R 5933:localhost:5900 user@third-machine.net

Here, the command means: connect with ssh to user@third-machine.net, and forward all connection attempts to the remote 5933 to port 5900 on the machine called localhost, which can be reached from your local machine. This is called reverse ssh tunnel.

After this successful setup, run VNC server at host listening to localhost on port 5900. Then, run VNC viewer at client looking at localhost on port 5900. Tadaa! now you can control the host’s screen. Now let’s see how to do it actually.

Procedure

Setting up VNC server on Ubuntu

We will be going to use x11vnc for our purpose because it makes all the settings very simple for Unix-like systems.

Step 1: Install x11vnc using sudo apt install x11vnc.

Step 2: Run command: x11vnc -ssh username@third-machine.net:33. And you are done with the reverse ssh command and VNC server starts listening to localhost on port 5900. You can also set a password for your VNC server by using -passwd XXXX with the above command. Add -forever to run it forever even when the ssh connection is lost and -shared to share the screen with more than one person. Look for other options with the man command.

Starting VNC Viewer

We will be using SSVNC software as a VNC Viewer on the client’s computer. It comes for many platforms. Ubuntu users can download using command: sudo apt install ssvnc. Others can download it from here.

Start ssvnc and then: – select “Use ssh”. – enter username@third-machine.net:33 in “VNC Host:Display” entry box and enter the password for VNC server in the “VNC Password” entry box. – click on connect. – enter the password for your ssh account if asked.

Share: