0

Using Ubuntu 22.04 LTS and after fresh installation, I am trying to set up x11vnc service to be executed on server boot (systemd). Currently, I can start the x11vnc manually in the server and am able to connect to the server from my client (port 5900). I need to configure x11vnc as a service to be permanently up and running when the server boots up.

To this direction, I have followed the 'normal' procedure of creating a service: https://help.ubuntu.com/community/VNC/Servers. Below is the configuration in my server:

sudo nano /lib/systemd/system/x11vnc.service
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -loop -forever -bg -rfbport 5900 -xkb -noxrecord -noxfixes -noxdamage -shared -norc -auth /run/user/1000/ubuntu/Xauthority -rfbauth /etc/x11vnc.pass
[Install]
WantedBy=multi-user.target

sudo nano /etc/systemd/system/x11vnc.service
[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service
[Service]
ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :1 -auth guess -rfbauth /etc/x11vnc.pass
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure
Restart-sec=2
[Install]
WantedBy=multi-user.target
                      

GDM accounts:

ubuntu@ubuntu-MS-7A94:~$ sudo loginctl 
SESSION  UID USER   SEAT  TTY 
  7 1000 ubuntu seat0 tty2
1 sessions listed.

but the service constantly fails:

ubuntu@ubuntu-MS-7A94:~$ sudo systemctl status x11vnc.service × x11vnc.service - "x11vnc"
 Loaded: loaded (/etc/systemd/system/x11vnc.service; enabled; vendor preset: enabled)
 Active: failed (Result: exit-code) since Thu 2022-08-04 16:48:18 EEST; 2s ago
Process: 16384 ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass (code=exited, status=1/FAILURE)
Main PID: 16384 (code=exited, status=1/FAILURE)
    CPU: 157ms
Αυγ 04 16:48:18 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Scheduled restart job, restart counter is at 5.
Αυγ 04 16:48:18 ubuntu-MS-7A94 systemd[1]: Stopped "x11vnc".
Αυγ 04 16:48:18 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Start request repeated too quickly.
Αυγ 04 16:48:18 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Αυγ 04 16:48:18 ubuntu-MS-7A94 systemd[1]: Failed to start "x11vnc".

I have not found any way till now to enable the x11vnc service. The Wayland option is set to false:

ubuntu@ubuntu-MS-7A94:~$ cat /etc/gdm3/custom.conf  | grep -i Wayland
WaylandEnable=false

The server's display:

ubuntu@ubuntu-MS-7A94:~$ echo $DISPLAY
:1

The Xauthority file is present in my home directory:

ubuntu@ubuntu-MS-7A94:~$ ll | grep Xauth
-rw-------  1 ubuntu ubuntu   60 Aug  4 17:11 .Xauthority

xauth list output:

ubuntu@ubuntu-MS-7A94:~$ xauth list
ubuntu-MS-7A94/unix:  MIT-MAGIC-COOKIE-1  c678b7bf6d0c8f05161fbfcafdd02652
#ffff#7562756e74752d4d532d37413934#:  MIT-MAGIC-COOKIE-1  c678b7bf6d0c8f05161fbfcafdd02652

x11vnc passwd file:

ubuntu@ubuntu-MS-7A94:~$ ll /etc/x11vnc.pass 
-rw-r--r-- 1 root root 8 Aug  4 16:42 /etc/x11vnc.pass

ubuntu@ubuntu-MS-7A94:~$ ll ~/.vnc/passwd
-rw------- 1 ubuntu ubuntu 8 Aug  4 13:24 /home/ubuntu/.vnc/passwd

journal logs:

Aug 04 17:56:04 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Aug 04 17:56:04 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Scheduled restart job, restart counter is at 3.
Aug 04 17:56:04 ubuntu-MS-7A94 systemd[1]: Stopped "x11vnc".
Aug 04 17:56:04 ubuntu-MS-7A94 systemd[1]: Started "x11vnc".
Aug 04 17:56:04 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:04 passing arg to libvncserver: -rfbauth
Aug 04 17:56:04 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:04 passing arg to libvncserver: /etc/x11vnc.pass
Aug 04 17:56:04 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:04 x11vnc version: 0.9.16 lastmod: 2019-01-05  pid: 25597
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25642]: xauth:  unable to generate an authority file name
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:05 -auth guess: failed for display=':1'
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:05 -auth guess: since we are root, retrying with FD_XDM=1
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25597]: 04/08/2022 17:56:05 -auth guess: failed for display=':1'
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Main process exited, code=exited, status=1/FAILURE
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Scheduled restart job, restart counter is at 4.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: Stopped "x11vnc".
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: Started "x11vnc".
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 passing arg to libvncserver: -rfbauth
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 passing arg to libvncserver: /etc/x11vnc.pass
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 x11vnc version: 0.9.16 lastmod: 2019-01-05  pid: 25713
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25758]: xauth:  unable to generate an authority file name
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 -auth guess: failed for display=':1'
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 -auth guess: since we are root, retrying with FD_XDM=1
Aug 04 17:56:05 ubuntu-MS-7A94 x11vnc[25713]: 04/08/2022 17:56:05 -auth guess: failed for display=':1'
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Main process exited, code=exited, status=1/FAILURE
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Scheduled restart job, restart counter is at 5.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: Stopped "x11vnc".
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Start request repeated too quickly.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: x11vnc.service: Failed with result 'exit-code'.
Aug 04 17:56:05 ubuntu-MS-7A94 systemd[1]: Failed to start "x11vnc".

Restarting the daemon, trying to enable and start the x11vnc service, server reboots did not work. I am not familiar with x11 configuration at all, but thought it would be easy to configure the x11vnc service, following common procedures mentioned in various websites. Is it something obvious I may miss in my configuration? Thanks in advance for helping!

2
  • try checking the logs for the service using sudo journalctl -u x11vnc. You can edit your question to paste the output here, so we can see what might be wrong and try to help.
    – Esther
    Commented Aug 4, 2022 at 14:44
  • Some journal logs also attached in the main post. Thanks @Esther
    – jim59
    Commented Aug 4, 2022 at 14:54

1 Answer 1

1

The problem is that your system can't find the .Xauthority file you are using. It is running x11vnc as root, with the option -auth guess, which means it should figure out what the xauth file is, and use that. However, how would a process running as root know to look in your home directory? You can explicitly pass the file to use for xauth though, using -auth /path/to/.Xauthority. That way it doesn't have to "guess" and will be able to find the file.

6
  • Thank you very much for the hint. This was for sure something I missed. The service now complains for missing authorization, thus not being able to open display:1. Journal: "Started "x11vnc".//passing arg to libvncserver: -rfbauth // passing arg to libvncserver: /etc/x11vnc.pass // x11vnc version: 0.9.16 lastmod: 2019-01-05 pid: 26181 // Authorization required, but no authorization protocol specified //XOpenDisplay(":1") failed.//Trying again with XAUTHLOCALHOSTNAME=localhost ... Could this be related to my x11vnc password file?
    – jim59
    Commented Aug 4, 2022 at 15:16
  • @jim59 I think that's because your "magic cookie" is saved under your username, and not root, see this answer. The difference between it running at boot and running manually may just be that at boot it runs as root and when you run manually it's running as your user. Do you want it to run as you or as root? You might be able to add some parameters to your service so it runs as you, in your home directory, etc
    – Esther
    Commented Aug 4, 2022 at 15:23
  • I just need the service to be running at boot, so is it that the cookie should belong to root? Do I need to make any modification to the ownership of the .Xauthority file? I am not familiar with the modifications needed so any hint will be more than welcomed! Thanks again.
    – jim59
    Commented Aug 4, 2022 at 15:37
  • hmm yes, you probably should make the .Xauthority file be owned by root, and only readable by it (possibly put a copy of it somewhere else, if you want to still use it yourself as well). Also probably follow the instructions in the answer I linked above to add the magic cookie info to root
    – Esther
    Commented Aug 4, 2022 at 15:39
  • things are getting so complicated with x11vnc service config that it might not deserve the effort. Is there any documentation I could follow to successfully set up the service from scratch after fresh installation? Troubleshooting turns out to be cumbersome. Tried to copy the cookie to the root user, but get a bad display name: //xauth: (argv):1: bad display name "ubuntu-MS-7A94/unix:" in "add" command// I cannot even clean the whole xauth list (due to bad display names). Changed ownership of .Xauthority to root, permissions (644+600) but nothing works. Thanks a lot for your time and hints
    – jim59
    Commented Aug 4, 2022 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .