Start by opening a terminal and entering the following command to install TightVNC server and the XFCE desktop manager core files:
$ sudo apt install tightvncserver XFCE4 XFCE4-goodies
After the packages are done installing, we need to configure a username and password that will be used to connect to the VNC server by a client. Create a password with this command:
$ vncpasswd
Next, let's configure VNC to start the XFCE desktop environment when a client connects. Use nano or the text editor of your preference (ex. Atom, Sublime) to create the following file:
$ nano ~/.vnc/xstartup
Insert the following few lines and then save your changes and exit the file:
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
With those changes made, edit the permissions of the file to make it executable:
$ chmod +x ~/.vnc/xstartup
VNC runs as a service on your system. In order for clients to connect, the VNC server must obviously be running and listening for incoming connection attempts. With our configuration complete, we are ready to start VNC server with the following command:
$ vncserver
VNC will use a new port for every remote desktop that is created. At this point, your system should be listening on port 5901 for incoming VNC connections. You can see this for yourself with the ss -ltn command:
$ ss -ltn
If you have the UFW firewall enabled, you'll need to open port 5901 so it doesn't block incoming VNC connections:
$ sudo ufw allow from any to any port 5901 proto tcp
You have to specify the port number (5901) when connecting with a vnc client : 192.168.1.40:5901