Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active March 11, 2022 18:31
Show Gist options
  • Save SomajitDey/3621cb92cf245ecdfeffda9668f9c8fc to your computer and use it in GitHub Desktop.
Save SomajitDey/3621cb92cf245ecdfeffda9668f9c8fc to your computer and use it in GitHub Desktop.
Setting up VNC for controlling remote desktop / screen sharing

In this tutorial we shall setup VNC such that we can remotely access a Linux desktop (Ubuntu 20.04) from a Windows 10 laptop. The Ubuntu desktop hosts the VNC server, whereas the Windows machine hosts the client.

Ref :

  1. https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-20-04
  2. https://www.linuxtopia.org/HowToGuides/VNC_setup_Linux_Windows.html

Server

  • sudo apt update
  • sudo apt install xfce4 xfce4-goodies During installation, you may be prompted to choose a default display manager for Xfce. A display manager is a program that allows you to select and log in to a desktop environment through a graphical interface. You’ll only be using Xfce when you connect with a VNC client, and in these Xfce sessions you’ll already be logged in as your non-root Ubuntu user. So for the purposes of this tutorial, your choice of display manager isn’t pertinent. Select either one and press ENTER. I chose gdm (the default).
  • sudo apt install tightvncserver
  • vncserver You’ll be prompted to enter and verify a password to access your machine remotely. NOTE: Note that if you ever want to change your password or add a view-only password, you can do so with the vncpasswd command.
  • Because you are going to be changing how the VNC server is configured, first stop the VNC server instance that is running on port 5901 with the following command vncserver -kill :1
  • Backup the original startup hook (script) before edits :
mv ~/.vnc/xstartup ~/.vnc/xstartup.original
  • Create a new startup hook ~/.vnc/xstartup containing only the following
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
  • chmod +x ~/.vnc/xstartup
  • Restart the server : vncserver -localhost

This properly sets up a VNC server listening on port 5901 at the Ubuntu machine.

Port forwarding

Forward port 5901 of the Windows machine (client) to port 5901 of the Ubuntu server using tunnel, ipns-link or ssh -L.

Client

  • At the Windows 10 laptop, download and install tightvnc.
  • We don't need the VNCserver here. So in the System Tray, right-click Tightvnc and shutdown the server.
  • Open the TightVNC Viewer app (search at Win+s). This opens a dialog box.
  • At the Remote Host field either write localhost:1 or localhost:5901. Click Connect.
  • When prompted for the password, enter the password you have setup your VNCserver @ Ubuntu with.
  • To open Terminal in xfce, open program launcher by using : Alt+F2. Then type Xfce Terminal and launch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment