2

Installing a new physical instance of Ubuntu 22.04 results in the Wayland desktop. I've switched that to x11 at the logon dialog (select "gear", chose xorg). This solution works for a virtual machine running 22.04 but does not seems to fix anything for my physical device. "The connection closed unexpectedly". Please advise if you have a suggestion. My x11vnc config with xinetd works perfectly on 20.04.

/etc/xinetd.d/x11vnc

service x11vnc { port = 5900 type = UNLISTED socket_type = stream protocol = tcp wait = no user = root server = /usr/bin/x11vnc server_args = -inetd -o /var/log/x11vnc.log -display :0 -auth /run/user/1000/gdm/Xauthority -many -bg disable = no }

Pilot6
  • 90,100
  • 91
  • 213
  • 324
IraDW
  • 31

2 Answers2

3

This worked for me on Ubuntu 22.04

Removed # in front of WaylandEnable=false like this:

sudo apt install x11vnc
sudo perl -i.bk -pe's/#(WaylandEnable=false)/$1/' /etc/gdm3/custom.conf

Rebooted remote computer to restart X, faster ways may exists:

sudo shutdown -r now

Then login to non-root user on physical remote desktop.

Then ssh'ed to remote by:

ssh -L5901:127.0.0.1:5900 me@remote

Then ran this (note :1 not :0 which worked in previous ubuntu)

x11vnc -display :1 -nopw -noxdamage -passwd po -scale 17/17 -ncache 10 &

In Remmina on local computer I configured this as server:

127.0.0.1:5901
Kjetil S.
  • 161
2

There are two basis ways to get x11vnc going to provide remote desktop:

  1. Log into Machine and then start x11vnc via commmand line

This only works if you have physical access to the machine

  1. 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:

  1. "greeter" x11vnc Service on its own TCP port (I use 5902)
  2. 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/

zebity
  • 371
  • This solution works fine on my Ubuntu 22.04, but my x11vnc failed to start at startup. I adjusted the x11vnc service to start when the x11vnc-login service fails, using the OnFailure directive, and now I can use port 5900 for both service. – study Apr 21 '23 at 02:46