The scenario here is that you have some sort of remote headless Linux server but would like to run some programs on them and get graphical access to them. The problem is that the remote server may be an image or VM without any virtual GPU and even if so, it is likely without KDE or Gnome, so there's no real way to do this, unless you follow our guide.
Install xvfb
apt install xvfb
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libxfont1 libxkbfile1 x11-xkb-utils xauth xfonts-base xfonts-encodings xfonts-utils xserver-common
The following NEW packages will be installed:
libxfont1 libxkbfile1 x11-xkb-utils xauth xfonts-base xfonts-encodings xfonts-utils xserver-common
xvfb
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 7703 kB of archives.
After this operation, 13.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 xauth amd64 1:1.0.9-1ubuntu2 [22.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libxfont1 amd64 1:1.5.1-1ubuntu0.16.04.4 [95.0 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxkbfile1 amd64 1:1.0.9-0ubuntu1 [65.1 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 x11-xkb-utils amd64 7.7+2 [153 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 xfonts-encodings all 1:1.0.4-2 [573 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 xfonts-utils amd64 1:7.7+3ubuntu0.16.04.2 [74.6 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 xfonts-base all 1:1.0.4+nmu1 [5914 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 xserver-common all 2:1.18.4-0ubuntu0.8 [27.7 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 xvfb amd64 2:1.18.4-0ubuntu0.8 [777 kB]
Fetched 7703 kB in 1s (4446 kB/s)
Selecting previously unselected package xauth.
(Reading database ... 51038 files and directories currently installed.)
Preparing to unpack .../xauth_1%3a1.0.9-1ubuntu2_amd64.deb ...
Unpacking xauth (1:1.0.9-1ubuntu2) ...
Selecting previously unselected package libxfont1:amd64.
Preparing to unpack .../libxfont1_1%3a1.5.1-1ubuntu0.16.04.4_amd64.deb ...
Unpacking libxfont1:amd64 (1:1.5.1-1ubuntu0.16.04.4) ...
Selecting previously unselected package libxkbfile1:amd64.
Preparing to unpack .../libxkbfile1_1%3a1.0.9-0ubuntu1_amd64.deb ...
Unpacking libxkbfile1:amd64 (1:1.0.9-0ubuntu1) ...
Selecting previously unselected package x11-xkb-utils.
Preparing to unpack .../x11-xkb-utils_7.7+2_amd64.deb ...
Unpacking x11-xkb-utils (7.7+2) ...
Selecting previously unselected package xfonts-encodings.
Preparing to unpack .../xfonts-encodings_1%3a1.0.4-2_all.deb ...
Unpacking xfonts-encodings (1:1.0.4-2) ...
Selecting previously unselected package xfonts-utils.
Preparing to unpack .../xfonts-utils_1%3a7.7+3ubuntu0.16.04.2_amd64.deb ...
Unpacking xfonts-utils (1:7.7+3ubuntu0.16.04.2) ...
Selecting previously unselected package xfonts-base.
Preparing to unpack .../xfonts-base_1%3a1.0.4+nmu1_all.deb ...
Unpacking xfonts-base (1:1.0.4+nmu1) ...
Selecting previously unselected package xserver-common.
Preparing to unpack .../xserver-common_2%3a1.18.4-0ubuntu0.8_all.deb ...
Unpacking xserver-common (2:1.18.4-0ubuntu0.8) ...
Selecting previously unselected package xvfb.
Preparing to unpack .../xvfb_2%3a1.18.4-0ubuntu0.8_amd64.deb ...
Unpacking xvfb (2:1.18.4-0ubuntu0.8) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for fontconfig (2.11.94-0ubuntu1.1) ...
Setting up xauth (1:1.0.9-1ubuntu2) ...
Setting up libxfont1:amd64 (1:1.5.1-1ubuntu0.16.04.4) ...
Setting up libxkbfile1:amd64 (1:1.0.9-0ubuntu1) ...
Setting up x11-xkb-utils (7.7+2) ...
Setting up xfonts-encodings (1:1.0.4-2) ...
Setting up xfonts-utils (1:7.7+3ubuntu0.16.04.2) ...
Setting up xfonts-base (1:1.0.4+nmu1) ...
Setting up xserver-common (2:1.18.4-0ubuntu0.8) ...
Setting up xvfb (2:1.18.4-0ubuntu0.8) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
First start the Xvfb server:
Xvfb&
Then use the xvfb-run command to start any program that needs graphical capabilities
xvfb-run someprogram
install x11vnc:
apt install x11vnc
/usr/bin/Xvfb :99 -ac -screen 0 1280x720x16&
export DISPLAY=:99
x11vnc -display :99 -localhost&
If this was a docker container or something else you don't care about security on you can change the x11vnc line to this (remove localhost):
x11vnc -display :99&
Once x11 vnc display starts it will normally run on port 5900 unless something else is already uses, it then it might run on port 5901.
The above will give you a screen with 1280x720 and 16 bit color as Xorg server screen#99. The 16-bit color is important otherwise, you'll get a horrible black and white screen over VNC if you try to use it.
Then we use x11vnc to tap into Xorg display#99 and listen on our local host.
The example below is running Firefox on a remote Linux Root/VPS server without any X windows running or installed and connecting over VNC via localhost SSH port forwarding.
xvfb, virtual, ssh, server, graphical, programs, workinstall, apt, install, lists, dependency, additional, packages, installed, libxfont, libxkbfile, xkb, utils, xauth, xfonts, encodings, xserver, upgraded, newly, kb, archives, mb, disk, http, archive, ubuntu, xenial, amd, updates, nmu, fetched, selecting, previously, unselected, database, directories, currently, preparing, unpack, xauth_, _amd, deb, unpacking, _, utils_, encodings_, _all, base_, common_, xvfb_, processing, triggers, db, libc, bin, fontconfig, configure, capabilities, someprogram,