First, install x11vnc
using e.g.
sudo apt -y install x11vnc
Now run this script as the user that is running the X11 session. The script needs to know the correct user to start x11vnc
as.
wget -qO- https://techoverflow.net/scripts/install-x11vnc.sh | sudo bash -s $USER
This will install a systemd
service like
[Unit] Description=VNC Server for X11 [Service] Type=simple User=uli Group=uli ExecStart=/usr/bin/x11vnc -display :0 -norc -forever -shared -autoport 5900 Restart=always RestartSec=10s [Install] WantedBy=multi-user.target
and automatically enable it on boot and start it.
You can connect to the computer using VNC now e.g. using:
vncviewer [hostname]