Red Hat Enterprise Linux 8.3 安装配置 VNC Server 完整教程(TigerVNC + systemd + 多用户)
RHEL 8.3 服务器没有图形界面时,可以通过 VNC 远程获得完整桌面环境。本文以 TigerVNC 为例,介绍从安装、配置多用户会话到用 systemd 设置开机自启的完整流程。
一、安装 VNC 服务端和桌面环境
如果服务器还没装桌面环境,先安装 GNOME(已有桌面可跳过):
dnf groupinstall "Server with GUI" -y
安装 TigerVNC 服务端:
dnf install tigervnc-server -y
验证版本(RHEL 8.3 的 TigerVNC 为 1.9.x):
vncserver -version
二、配置 VNC 用户
创建用于远程登录的普通用户并设置密码:
useradd vncuser
passwd vncuser
切换到该用户,设置 VNC 连接密码(与系统密码相互独立,最多 8 位有效):
su - vncuser
vncpasswd
- 输入两次 VNC 密码
- 询问是否设置 view-only 密码时一般选 n
- 密码保存在
~/.vnc/passwd
三、配置 systemd 服务(支持多用户)
RHEL 8 提供了服务模板,按 /etc/tigervnc/vncserver.users 中的配置为每个用户分配一个显示号:
# /etc/tigervnc/vncserver.users
:1=vncuser
:2=anotheruser
如需调整全局选项(分辨率、桌面会话等),编辑 /etc/tigervnc/vncserver-config-mandatory(强制生效)或 /etc/tigervnc/vncserver-config-defaults(默认值):
# /etc/tigervnc/vncserver-config-defaults
session=gnome
geometry=1920x1080
localhost=no
alwaysshared
session=gnome指定使用 GNOME 桌面localhost=no允许非本机连接(只本机连可去掉,然后走 SSH 隧道更安全)alwaysshared允许多客户端同时连接
为用户写一份 xstartup 启动脚本(防止连上后黑屏):
cat > ~/.vnc/xstartup << 'EOF'
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec /etc/X11/xinit/xinitrc
EOF
chmod +x ~/.vnc/xstartup
如果系统启用了 SELinux(RHEL 8.3 默认 enforcing),给 xstartup 打上正确的安全上下文:
restorecon -v /home/vncuser/.vnc/xstartup
四、启动服务并设置开机自启
# 启动显示号 :1 的 VNC 会话
systemctl start vncserver@:1
# 开机自启
systemctl enable vncserver@:1
# 查看状态
systemctl status vncserver@:1
多用户就多配几个显示号,比如 systemctl enable vncserver@:2 对应 vncserver.users 里的 :2=anotheruser。
五、防火墙放行
VNC 端口规则:显示号 N 对应 TCP 端口 5900+N(:1 就是 5901)。放行单个端口:
firewall-cmd --permanent --add-port=5901/tcp
firewall-cmd --reload
或使用 firewalld 自带的 vnc-server 服务(放行 5900-5903):
firewall-cmd --permanent --add-service=vnc-server
firewall-cmd --reload
六、客户端连接
Windows 用 RealVNC Viewer / TightVNC,Mac 用内置「前往 → 连接服务器」(vnc://IP:5901),Linux 用 vinagre 或 TigerVNC viewer,地址填 服务器IP:5901(客户端通常也可写 IP:1),输入第二步设置的 VNC 密码即可进入 GNOME 桌面。
更安全的做法是不对公网开放 5901,保持 localhost=yes,客户端通过 SSH 隧道连接:
ssh -L 5901:localhost:5901 vncuser@服务器IP
# 然后客户端连接 localhost:5901
七、常见问题
连接后黑屏 / 只剩灰屏
多半是 xstartup 没有可执行权限或没写桌面启动命令,检查第三步的脚本与 chmod +x,再看 ~/.vnc/*:1.log 日志。
密码错误但确认输入无误
VNC 密码只取前 8 位,检查是否与系统登录密码混淆——它们是两套独立的密码。
服务启动失败
journalctl -u vncserver@:1 -e
cat /home/vncuser/.vnc/*.log
常见原因:vncserver.users 里用户名写错、用户没有跑过 vncpasswd(无 ~/.vnc/passwd)、SELinux 拦截 xstartup。






