X11vnc + systemd on rocky9

Anyone have luck getting x11vnc running on Rocky 9 as a systemd service? I’ve scoured the web and have not seen an article for this on Rocky, mostly for Ubuntu/Debian.

My goal is to have x11vnc working, even at the login screen.

I’m able to get x11vnc running manually while logged in using the command below:

/usr/bin/x11vnc -passwd 1234 -display :1 -auth /run/user/1000/gdm/Xauthority -forever -bg -shared

However, when setting up the systemd service, the application will not start up

[Unit]
Description=x11vnc server
After=multi-user.target network.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -passwd 1234 -forever -bg -shared -auth guess

[Install]
WantedBy=multi-user.target

If I tweak the ExecStart to include the display, it will throw out an SELinux warning

Jan 25 17:49:56 localhost setroubleshoot[2344]: SELinux is preventing /usr/bin/xauth from append access on the unix_stream_socket unix_stream_socket. For complete SELinux messages run: sealert -l bf083e83-d316-4ca3-998a-9f3c1204c1f0

In my previous Centos7 build, this was the systemd config and worked flawlessly

/usr/bin/x11vnc -inetd -o /var/log/x11vnc.log -display :0 -auth /var/gdm/:0.Xauth -passwd 1234 -forever -bg

I’ve been able to get the systemd service running, however it does not appear to be accepting connections. The service has to be running as the GDM user.

The issue now is something about systemd socket access, I am not sure how to fix. Any help would be great!

Jan 27 16:38:57 localhost x11vnc[2128]: 27/01/2023 16:38:57
Jan 27 16:38:57 localhost x11vnc[2128]: 27/01/2023 16:38:57 Unable to establish connection with systemd socket
Jan 27 16:38:57 localhost x11vnc[2128]: 27/01/2023 16:38:57 setsockopt failed: can't set TCP_NODELAY flag, non TCP socket?: Socket operation on non-socket

[Unit]
Description=Start x11vnc server at startup.
After=multi-user.target network.target

[Service]
Type=simple
User=gdm
Group=gdm
ExecStart=/usr/bin/x11vnc -inetd -passwd 1234 -forever -shared -bg -display :0 -auth /run/user/42/gdm/Xauthority


[Install]
WantedBy=multi-user.target

Seems to be an issue with rocky9 in itself, xinetd will run with no issues on rocky8.

If it relies on the UI being available, since you are using gdm, and also X that means you would probably want to add:

After=graphical.target

assuming of course that the ExecStart command when ran manually from the console does listen and work as expected.

I tested this right after Rocky Linux 9 was released - the problem is that the x11vnc package requires X11 display server and Rocky Linux 9 uses Wayland display server by default - x11vnc works fine on Rocky Linux 9 Mate which still uses X11 display server.

Hi, thank you for replying!

Do you mind sharing your configuration?

The closest I was able to get was by disabling wayland, I could get x11vnc to start on launch at the login screen level. However, once logged in, it would only display a black window through VNC. If the service is stopped and restarted after the login has happened, then it would be fine, but I can’t get a seemless x11vnc configuration that operates, regardless of who is logged in. Been stumped on this one for a while.

Sure!

The content of the service file (x11vnc.service) is attached below.

[Unit]
Description=VNC server for the current X11 session
After=display-manager.service

[Service]
ExecStart=/usr/bin/x11vnc -auth guess -cursor arrow -display :0 -forever -loop -noallinput -nobell -nodpms -noipv6 -nomodtweak -nopw -norc -nossl -noxdamage -noxfixes -noxkb -noxrecord -o /var/log/x11vnc.log -reopen -repeat -rfbauth /root/.vnc/x11vnc.passwd -rfbport 5900 -rfbversion 3.8 -shared
Restart=on-failure
RestartSec=3

[Install]
WantedBy=graphical.target

Thanks for reply and for providing your systemd info - unfortunately it still does not work.

I’ve disabled wayland, and when I run x11vnc manually via the GUI, connections are accepted, so it is not a firewall issue.

the service appears to be running, however when attempting to connect, nothing happens and just times out.

Besides disabling wayland, the config is very much vanilla.

[root@hostname ~]# uname -r
5.14.0-162.12.1.el9_1.0.2.x86_64

[root@hostname~]# sudo systemctl status vnc.service
● vnc.service - VNC server for the current X11 session
     Loaded: loaded (/etc/systemd/system/vnc.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2023-02-21 12:35:19 JST; 1min 29s ago
   Main PID: 1464917 (x11vnc)
      Tasks: 1 (limit: 818975)
     Memory: 3.1M
        CPU: 3.471s
     CGroup: /system.slice/vnc.service
             └─1464917 /usr/bin/x11vnc -auth guess -cursor arrow -display :0 -forever -loop -noallinput -nobell -nodpms -noipv6 -nomodtweak -nopw -norc -nossl -noxdamage -noxfixes -noxkb -noxrecord -o /var/log/x11vnc.log -reopen -repeat -rfbauth /root/.vnc/x11vnc.passwd>

Feb 21 12:36:39 hostname x11vnc[1464917]:  --- x11vnc loop: sleeping 2000 ms ---
Feb 21 12:36:41 hostname x11vnc[1464917]:  --- x11vnc loop: 33 ---
Feb 21 12:36:42 hostname x11vnc[1464917]:  --- x11vnc loop: waiting for: 1468574
Feb 21 12:36:42 hostname x11vnc[1464917]:  --- x11vnc loop: sleeping 2000 ms ---
Feb 21 12:36:44 hostname x11vnc[1464917]:  --- x11vnc loop: 34 ---
Feb 21 12:36:44 hostname x11vnc[1464917]:  --- x11vnc loop: waiting for: 1468688
Feb 21 12:36:44 hostname x11vnc[1464917]:  --- x11vnc loop: sleeping 2000 ms ---
Feb 21 12:36:46 hostname x11vnc[1464917]:  --- x11vnc loop: 35 ---
Feb 21 12:36:47 hostname x11vnc[1464917]:  --- x11vnc loop: waiting for: 1468802
Feb 21 12:36:47 hostname x11vnc[1464917]:  --- x11vnc loop: sleeping 2000 ms ---

@acte28
As I can see your x11vnc service is in a loop and therefore no client can connect to it.

it’s a copy/paste of service file that you sent, which also include the -loop option

I tested your suggestion of running Rocky9 on MATE, and x11vnc seems to work fine! Really appreciate it. It’s a shame since MATE shows an antiquated UI, but we’ll take it! I suppose the limitation comes from the default gnome within Rocky9.