就如前篇文章所言,苦于经由 X11 转发的卡顿感,遂决定安装 TightVNC 后走 VNC 协议进行连接。
XRDP
正常来说安装 XRDP 走 RDP 协议更为方便,另外普遍来说 Windows 系统都已经默认安装了该客户端。
apt install xrdp
或许就是因为没有安装桌面环境,RDP 无法启动转而使用 VNC 协议。
TigerVNC
安装 TigerVNC 和依赖
- 安装 TigerVNC 和依赖:
apt update apt install tigervnc-standalone-server tigervnc-common dbus-x11
tigervnc-standalone-server:提供更现代的 VNC 服务器,支持 X 扩展。 - 以普通用户身份运行 vncpasswd 设置密码:
vncpasswd
根据需求自行设置密码。
启动 TigerVNC 会话
vncserver -depth 24 -geometry 1920x1080 -localhost no :0
输出:
New Xtigervnc server 'UnitedStates.YunLtd.cyzwb.com:0 (root)' on port 5900 for display :0. Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /tmp/tigervnc.z3qhtT/passwd UnitedStates.YunLtd.cyzwb.com:0 to connect to the VNC server.
客户端连接
使用IP:5900或vnc://ip:5900连接测试是否正常。
开机自启
编辑/etc/systemd/system/vncserver@.service文件:
[Unit] Description=System VNC Server for display %i After=syslog.target network.target # 明确服务冲突:同一端口只能启动一个VNC实例 Conflicts=vncserver@%i.service [Service] # 运行用户:必须指定普通用户,禁止root运行(安全风险) User=%I Group=%I Type=forking ExecStart=/usr/bin/vncserver -depth 24 -geometry 1920x1080 -localhost no -SecurityTypes TLSVnc -PasswordFile ~/.vnc/passwd :%i # 优雅停止:先杀进程再清理临时文件 ExecStop=/usr/bin/vncserver -kill :%i ExecStopPost=/bin/rm -rf /tmp/.X11-unix/X%i # 重载逻辑:先停止再启动(VNC不支持热重载) ExecReload=/usr/bin/vncserver -kill :%i; /usr/bin/vncserver -depth 24 -geometry 1920x1080 -localhost no -SecurityTypes TLSVnc -PasswordFile ~/.vnc/passwd :%i # 重启策略:仅非预期退出时重启,避免死循环 Restart=on-failure RestartSec=5 # 文件句柄限制:适配高并发场景 LimitNOFILE=100000 # 环境变量:强制使用UTF-8编码,避免乱码 Environment="LANG=en_US.UTF-8" # 进程隔离:限制服务权限,提升安全性 PrivateTmp=true ProtectSystem=strict ProtectHome=true Environment="DISPLAY=:%i" [Install] WantedBy=multi-user.target
然后执行:
systemctl daemon-reload systemctl enable vncserver@0 systemctl start vncserver@0 systemctl status vncserver@0
参考
- 在 Debian 13(以及 12)上安装和配置 tightvncserver 并让普通用户使
https://www.cnblogs.com/HGNET/p/19628342
ChiuYut
2026年05月12日