Set up a VNC server on Linux


# Install TightVNC.
sudo apt update
sudo apt install -y tightvnc

# Start a new VNC server session.
vncserver :1

The first time this is run, TightVNC will probably ask you to set up a password.

Note that the display number in the last command (e.g., :1) affects the port number through which a client should connect to the server. The default VNC port starts at 5900; so using display :1 means that the client must connect to the server on port 5901; using a display of :2 means connecting on port 5902; etc.

Once this is up and running, use a client like Remmina to connect to the server.

NOTE: VNC connections are not required to use encryption. At least, that's how things have been historically; whether that has changed in modern times, I don't know. But to ensure that the connection is encrypted, I recommend tunnelling the connection over SSH. Remmina makes this easy. When setting up a standard VNC connection in Remmina, follow these steps:

  1. When setting up a standard VNC connection, you'd normally enter the IP address and port into the "Server" field in the "Basic" settings (e.g., "123.456.789.000:5901"). To use SSH tunnelling, however, set the server and port to "localhost:5901".

  2. In the "SSH Tunnel" tab, click the "Enable SSH tunnel" button.

  3. Select "Custom" and set IP address and port using your predefined SSH settings. For example, to connect over port 22, give the field a value like "123.456.789.000:22".

  4. I tend to use public key encryption for all of my SSH connections, if possible. If that's what you're using, then set the "Authentication type" to "Public key (automatic)".

  5. Set the SSH username in the "Username" field.

  6. Check the box next to the "SSH private key file" field, and then browse the filesystem to select the relevant private key file.

  7. Click the "Save" button at the bottom.

And that's it!

NOTE: If for some reason nothing appears when you connect and the screen remains blank and gray, then you may need to follow these instructions.