There are two basis ways to get x11vnc going to provide remote desktop:
- Log into Machine and then start x11vnc via commmand line
This only works if you have physical access to the machine
- Create a startup script/s that starts x11vnc on machine boot
This allows you to have complete remote access to your machine and results in the login "greeter" being availeble and then the remote desktop, once you have logged.
Since Ubuntu 17 getting (2) going has required need to set up a hack solution as the "greeter" and "user" use different X11 DISPLAYs and the Xorg server instance run under different user ids (uid), user == gdm for "greeter" and YOUR_USER_ACCOUNT for Remote Desktop.
The result is that you need to run two seperate services:
- "greeter" x11vnc Service on its own TCP port (I use 5902)
- User Desktop x11vnc Service on its own TCP port (I use standard port 5900)
The other complication is that for years the Xauthourity token as in the users home directory under .X11/Xauthority and now it is keep in: /run/user//gdm/Xauthority
The hack results in need to first connect to VNC port 5902 to login via "greeter" and then shut that window and connect to desktop via VNC port 5900.
Here is sample systemd startup scripts for "greeter" (login) and Desktop.
GREETER (startup script):
$ cat /lib/systemd/system/x11vnc-login.service
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
User=gdm <<=== Ubuntu 21.04 need process DISPLAY owner id
ExecStart=/usr/bin/x11vnc -auth /run/user/126/gdm/Xauthority -forever -loop -repeat -rfbauth /home/gdm/.vnc/passwd -rfbport 5902 -shared -display :0
[Install]
WantedBy=multi-user.target
DESKTOP (startup script):
$ cat /lib/systemd/system/x11vnc.service
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
User=WHO <<=== Now the session user
ExecStart=ExecStart=/usr/bin/x11vnc -auth /run/user/1XXX/gdm/Xauthority -forever -loop -noxdamage -repeat -rfbauth /home/WHO/.vnc/passwd -rfbport 5900 -shared -xkb -display :1
Or if you have a problem with keys not working you might
need to add: -skip_keycodes CODE,CODE... flag
See below for more details
[Install]
WantedBy=multi-user.target
Once you have added the systemd scripts you should enable/start:
# sudo systemctl enable x11vnc-login
# sudo systemctl enable x11vnc
# sudo systemctl start x11vnc-login
# sudo systemctl start x11vnc
Oh, yes for this to work you have to disable "Wayland", as x11vnc only works with X11 and not with Wayland.
Disable "Wayland" display manager by editing /etc/gdm3/custom.conf and setting WaylandEnable=false
As this has a "habit" of breaking with each Ubuntu update I have documented the diagnosis and fixup details (for future reference) in my blog: https://tips.graphica.com.au/ubuntu-and-remote-gnome-desktop/
sudo ufw allow 5000:6000/tcp
– Igór Bellmónt Sep 21 '22 at 11:38