x11vnc systemd 服务失败

x11vnc systemd 服务失败

使用 Ubuntu 22.04 LTS 并全新安装后,我尝试设置 x11vnc 服务以在服务器启动时执行(systemd)。目前,我可以在服务器中手动启动 x11vnc,并能够从我的客户端(端口 5900)连接到服务器。我需要将 x11vnc 配置为服务,以便在服务器启动时永久启动并运行。

为了这个方向,我遵循了创建服务的“正常”程序: https://help.ubuntu.com/community/VNC/Servers。下面是我的服务器中的配置:

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 账户:

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

但服务不断失败:

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".

到目前为止,我还没有找到任何方法来启用 x11vnc 服务。Wayland 选项设置为 false:

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

服务器的显示:

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

Xauthority 文件位于我的主目录中:

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

xauth 列表输出:

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

x11vnc 密码文件:

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

日记帐日志:

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".

重新启动守护进程,尝试启用并启动 x11vnc 服务,服务器重新启动不起作用。我对 x11 配置一点也不熟悉,但我认为按照各个网站中提到的常见程序配置 x11vnc 服务会很容易。我的配置中可能遗漏了一些明显的内容吗?提前感谢帮助!

答案1

问题是您的系统找不到您正在使用的 .Xauthority 文件。它x11vnc以 root 身份运行,使用选项-auth guess,这意味着它应该找出 xauth 文件是什么,并使用它。但是,以 root 身份运行的进程如何root知道在您的主目录中查找?您可以使用 明确传递要用于 xauth 的文件-auth /path/to/.Xauthority。这样它就不必“猜测”并能够找到该文件。

相关内容