rk3576 Ubuntu 22.04 安装与配置 VNC(TigerVNC + x11vnc)

本文汇总在 rk3576(Ubuntu 22.04)上完成 VNC 远程桌面配置的全过程,目标是同时满足两种使用场景:

  • 虚拟桌面会话 :通过 TigerVNC 启动独立桌面(:1,端口 5901),适合多人/后台运行,不影响 HDMI 物理屏。
  • 镜像 HDMI 物理桌面 :通过 x11vnc 镜像本机正在显示的桌面(:0,端口 5900),适合"远程控制本机屏幕"。

为安全起见,两路 VNC 都配置为 仅监听本机 localhost ,建议通过 SSH 隧道连接。

1. 安装依赖

bash 复制代码
sudo apt-get update
sudo apt-get install -y \
  tigervnc-standalone-server tigervnc-common \
  xfce4 xfce4-goodies dbus-x11 \
  x11vnc

2. 配置 TigerVNC(虚拟桌面 :1 / 5901)

2.1 创建 VNC 启动脚本

文件:[/home/firefly/.vnc/xstartup](file:///home/firefly/.vnc/xstartup)

sh 复制代码
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4

并赋予可执行权限:

bash 复制代码
chmod +x ~/.vnc/xstartup

2.2 设置 TigerVNC 配置

文件:[/home/firefly/.vnc/config](file:///home/firefly/.vnc/config)

ini 复制代码
geometry=1280x800
depth=24
localhost

说明:

  • depth=24:避免低色彩导致的偏色。
  • localhost:仅允许本机连接(配合 SSH 隧道更安全)。

2.3 设置 VNC 密码

bash 复制代码
vncpasswd

会生成 ~/.vnc/passwd(权限应为 600)。

2.4 配置 systemd user 服务(TigerVNC)

文件:[/home/firefly/.config/systemd/user/vncserver.service](file:///home/firefly/.config/systemd/user/vncserver.service)

ini 复制代码
[Unit]
Description=TigerVNC server on display :1
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/vncserver :1
ExecStop=/usr/bin/vncserver -kill :1
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

启用并启动:

bash 复制代码
systemctl --user daemon-reload
systemctl --user enable --now vncserver.service

若希望在未登录情况下也能自启动 user service:

bash 复制代码
sudo loginctl enable-linger firefly

3. 配置 x11vnc(镜像 HDMI 桌面 :0 / 5900)

TigerVNC 的 :1 是"独立桌面",不会影响 HDMI 物理屏幕。如果需要"远程控制 HDMI 上的桌面(:0)",使用 x11vnc。

3.1 配置 systemd user 服务(x11vnc)

文件:[/home/firefly/.config/systemd/user/x11vnc.service](file:///home/firefly/.config/systemd/user/x11vnc.service)

ini 复制代码
[Unit]
Description=Mirror local X11 desktop via x11vnc on :0
After=graphical-session.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -display :0 -auth /home/firefly/.Xauthority -rfbauth /home/firefly/.vnc/passwd -rfbport 5900 -localhost -forever -shared -noxdamage -repeat
Restart=on-failure
RestartSec=3

[Install]
WantedBy=default.target

说明:

  • -display :0:镜像 HDMI 的本机桌面。
  • -auth ~/.Xauthority:读取当前用户的 X11 授权。
  • -rfbauth ~/.vnc/passwd:复用 VNC 密码。
  • -localhost:仅本机监听(建议 SSH 隧道连接)。

启用并启动:

bash 复制代码
systemctl --user daemon-reload
systemctl --user enable --now x11vnc.service

4. 连接方式(Windows RealVNC Viewer)

本机 Ubuntu 上实际监听的是:

  • :0 镜像桌面:127.0.0.1:5900
  • :1 虚拟桌面:127.0.0.1:5901

推荐从 Windows 先建立 SSH 隧道,再用 RealVNC Viewer 连 127.0.0.1

4.1 连接镜像 HDMI 桌面(推荐)

PowerShell:

bash 复制代码
ssh -L 5900:localhost:5900 firefly@<UBUNTU_IP>

RealVNC Viewer 连接:

  • 127.0.0.1:5900

4.2 连接 TigerVNC 虚拟桌面

PowerShell:

bash 复制代码
ssh -L 5901:localhost:5901 firefly@<UBUNTU_IP>

RealVNC Viewer 连接:

  • 127.0.0.1:5901

5. 常用检查与维护

查看服务状态:

bash 复制代码
systemctl --user status vncserver.service
systemctl --user status x11vnc.service

重启服务:

bash 复制代码
systemctl --user restart vncserver.service
systemctl --user restart x11vnc.service

查看端口监听(应为 127.0.0.1):

bash 复制代码
ss -ltnp | grep -E ':5900 |:5901 ' || true

6. 常见问题

6.1 颜色异常/偏色(RealVNC Viewer)

若出现偏色、色阶断层,通常是 Viewer 把色深降到了 8-bit。

处理方法:在 RealVNC Viewer 的连接属性里把颜色/质量改为 Full/True colour(24-bit),然后重连。

6.2 VNC 点鼠标 HDMI 屏幕无反应

说明你连接的是 TigerVNC 的虚拟桌面 :1(5901),它不控制 HDMI 的 :0

要控制 HDMI 屏幕:

  • 通过 SSH 隧道连接 127.0.0.1:5900(x11vnc)。
相关推荐
qq_273900233 小时前
Apptainer 将 Ubuntu 本地 Conda 环境打包为 Singularity(SIF)镜像
linux·ubuntu·conda
小草cys4 小时前
【有问题未解决】Ubuntu arm版的桌面分辨率修改
linux·arm开发·ubuntu
鱼是一只鱼啊4 小时前
安装WSL及Ubuntu遇到问题安全频道支持出错
linux·安全·ubuntu
qinyia4 小时前
在Ubuntu 22.04.5 LTS上安装MySQL 8并设置root密码的完整协作流程
mysql·ubuntu·adb
robitmind4 小时前
操作input子系统,用模拟按键输入解锁ubuntu锁屏
linux·运维·ubuntu
DONG9994 小时前
To create a RAM-based block device in Ubuntu.
ubuntu
.小墨迹5 小时前
开源的自动驾驶框架
c++·人工智能·学习·算法·ubuntu·开源·自动驾驶
hhy_smile15 小时前
Ubuntu24.04 环境配置自动脚本
linux·ubuntu·自动化·bash