我想在Debian机器上设置VNC服务器,作为服务运行,这样我就可以打开远程机器并访问它,而不需要实际存在。
一种选择是在用户总线中设置它:
$ systemctl --user cat vnc.service
# /home/stew/.config/systemd/user/vnc.service
[Unit]
Description=VNC Server
After=default.target
[Service]
ExecStart=x11vnc -nevershared -forever -nopw
[Install]
WantedBy=default.target这是可行的,但仍然需要me物理地坐在终端上登录到gdm3以获得XAUTHORITY,然后我才能做任何远程工作。如果我在登录ssh之前登录gdm3,则服务将失败。我通过在AutomaticLoginEnable=True和AutomaticLogin=stew中使用/etc/gdm3/daemon.conf来解决这个问题。
相反,我希望能够使用VNC,而不需要首先作为特定的用户登录(类似于RDP)。我认为最好的方法是使用-nopw进入gdm3屏幕。
我试着用:
$ systemctl cat vnc.service
# /etc/systemd/system/vnc.service
[Unit]
Description=VNC Service (system-wide)
After=graphical.target
[Service]
ExecStart=x11vnc -auth /run/user/116/gdm/Xauthority -display :0 -nopw
[Install]
WantedBy=graphical.target我使用这个命令找到了XAUTHORITY路径,显示该路径属于UID 116 (system:Debian-gdm)。
stew ~ $ ps wwwwaux | grep auth
root 1033 0.1 0.5 189548 63596 tty1 Sl+ 14:32 0:00 /usr/lib/xorg/Xorg vt1 -displayfd 3 -auth /run/user/116/gdm/Xauthority -nolisten tcp -background none -noreset -keeptty -novtswitch -verbose 3我还需要在WaylandEnable=false中设置/etc/gdm3/daemon.conf,因为VNC似乎不适合Wayland。
起初,这似乎很有效。我得到了gdm登录屏幕。但是,当我试图以用户身份登录时,auth将被传输到另一个用户,并且我被断开连接。
有没有办法设置VNC,这样我就可以通过gdm登录?
发布于 2021-04-13 14:32:25
这不是无缝的,但这里有一个解决方案。
我们从一个运行VNC并将我们连接到GDM登录屏幕的服务开始。
$ systemctl cat vnc-gdm.service
# /etc/systemd/system/vnc-gdm.service
[Unit]
Description=VNC Server (gdm)
After=graphical.target
[Service]
ExecStart=bash -c 'x11vnc -auth /run/user/$(id -u Debian-gdm)/gdm/Xauthority -display :0 -nopw'
Restart=on-failure
RestartSec=3
[Install]
WantedBy=graphical.target然后,对于我们想要支持的每个用户,我们添加另一个VNC服务。这一次将在ExecStartPre=中每2秒轮询一次,以查看这个用户是否有一个Xorg实例。当发生这种情况时,它将停止vnc-gdm.service释放端口5900,以便它自己的x11vnc实例可以绑定到它。
然后运行x11vnc。
$ systemctl cat vnc-stew.service
# /etc/systemd/system/vnc-stew.service
[Unit]
Description=VNC Server (stew)
After=graphical.target
[Service]
User=stew
ExecStartPre=sh -c 'while ! pgrep -U stew Xorg; do sleep 2; done'
ExecStartPre=+systemctl stop vnc-gdm.service
ExecStart=x11vnc -many -shared -display :1 -auth /home/stew/.Xauthority -rfbauth /home/stew/.vnc/passwd
Restart=on-failure
RestartSec=3
[Install]
WantedBy=graphical.target我说这不是无缝的,因为一旦您通过gdm登录:您的连接被切断,您需要重新连接到您的新显示器。我还没有对多个用户进行测试。而且,如果我注销了X-会话,我很确定我将无法返回。
我也不喜欢我们如何在systemctl stop中使用ExecStartPre=。
发布于 2022-02-28 14:50:44
在运行Gnome桌面的Debian 11 (Bullseye)上,Stewart关于在gdm欢迎会话上运行x11vnc的服务定义(Stewart的第一个代码块)几乎对我起了作用,但它失败了,因为x11nvc抱怨无法访问私有资源。我通过插入"sudo -u Debian“解决了这个问题,导致行:
...
ExecStart=bash -c 'sudo -u Debian-gdm x11vnc -auth /run/user/$(id -u Debian-gdm)/gdm/Xauthority -display :0 -nopw'
...发布于 2022-06-01 06:14:55
https://unix.stackexchange.com/questions/644886
复制相似问题