server 软件

  • x11vnc

    • 直接共享已有 session
    • -create 创建新的 session
  • tigervnc

    • 默认创建新的 headless session
    • 使用 x0vncserver 命令共享已有屏幕(display)

使用方法

共享现有屏幕 session

1
2
3
4
5
6
# x11vnc
❯ x11vnc -auth /run/user/1000/gdm/Xauthority -display :0 -forever   


# x0vncserver
DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority x0vncserver -display :0 -rfbauth $XDG_CONFIG_HOME/tigervnc/passwd

启动

tigervnc 设置

vim ~/.config/tigervnc/config

1
2
3
4
session=LXDE
geometry=1920x1080
localhost=no
alwaysshared
  • localhost=no 表示允许外部访问

tigervnc + x0vncserver + systemd

❯ systemctl --user start  x0vncserver.service

x0vncserver.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Remote desktop service (VNC)

[Service]
Type=simple
ExecStartPre=/bin/sh -c 'while ! pgrep -U "$USER" Xorg; do sleep 2; done'
Environment=DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority 
ExecStart=x0vncserver -rfbauth %h/.config/tigervnc/passwd

[Install]
WantedBy=default.target
  • 注意设置了环境变量:

    • DISPLAY=:0
    • XAUTHORITY=/run/user/1000/gdm/Xauthority

tigervnc + systemd 相同的 systemd 使用

❯ sudo systemctl enable --now vncserver@:1.service

连接

:0 连接到 5900

:1 连接到 5901 依次类推

重要概念

password

tigervnc 创建方法

命令 vncpasswd

x11vnc

x11vnc -usepw

-auth

auth 文件

eg:

  1. 通过命令查找

    1
    2
    3
    4
    5
    6
    
    who | grep "(:.)"
    # 或者
    ps aux | grep Xorg | grep -v grep
    # 输出 -------
    sawyer   :0           2025-11-18 13:33 (:0)
    sawyer      1115  4.6  0.3 26139436 216904 tty2  Sl+  13:33   0:44 /usr/lib/Xorg vt2 -displayfd 3 -auth /run/user/1000/gdm/Xauthority -nolisten tcp -background none -noreset -keeptty -novtswitch -verbose 3
  2. 指定 auth

    1
    2
    3
    4
    5
    6
    
    # x11vnc
    ❯ x11vnc -auth /run/user/1000/gdm/Xauthority -display :0 -forever   
    
    
    # x0vncserver
    DISPLAY=:0 XAUTHORITY=/run/user/1000/gdm/Xauthority x0vncserver -display :0 -rfbauth $XDG_CONFIG_HOME/tigervnc/passwd

注意

他们只能和 X11 共同工作良好,wayland 兼容性不好

通过 修改 /etc/gdm/custom.conf:

1
WaylandEnable=false

禁用 wayland