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)。
相关推荐
通信小小昕16 小时前
Ubuntu 26.04 中文输入法安装
linux·运维·ubuntu
CedarQR18 小时前
万字长文:从零在 RK3588 上部署 PaddleSpeech 中文 TTS 全流程(FastSpeech2 + HiFiGAN)
开发语言·c++·嵌入式硬件·ubuntu·json
雷工笔记21 小时前
Ubuntu迁移记录
笔记·ubuntu
一叶龙洲1 天前
ubuntu26.04 xfce美化成mac
服务器·ubuntu·macos
一叶龙洲1 天前
wslg打开Ubuntu24.04默认打开图形界面
linux·服务器·数据库·ubuntu
敖行客 Allthinker2 天前
Parallels Ubuntu虚拟机项目如何让手机访问?完整解决方案
linux·运维·ubuntu
keyipatience2 天前
线程栈与TLS和线程互斥
java·linux·服务器·开发语言·ubuntu
观山岳五楼2 天前
Ubuntu 24 怎么使用Ubuntu 20 的镜像源
linux·运维·ubuntu
辰痕~2 天前
物理机装Linux操作系统(Ubuntu为例)
linux·ubuntu
Byron Loong2 天前
【Git】如何检查 Ubuntu 系统上 gitLab 是否开启
git·ubuntu·gitlab