CentOS 上使用 VNC 的完整步骤
一 环境准备
yum groupinstall "GNOME Desktop" -yyum -y install epel-release && yum groupinstall Xfce -yyum install tigervnc-server -yuseradd vncuser && passwd vncuser;随后切换到该用户进行后续配置:su - vncuser。二 安装与配置 VNC 服务
vncpasswd,按提示输入并确认;可设置只读密码(可选)。cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service[Service]
Type=forking
User=vncuser
ExecStartPre=-/usr/bin/vncserver -kill %i >/dev/null 2>&1
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/vncuser/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
systemctl daemon-reloadsystemctl enable vncserver@:1.service && systemctl start vncserver@:1.service三 配置桌面环境与分辨率
vim ~/.vnc/xstartup,确保启动你安装的桌面环境。示例(启动 Xfce):#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
exec startxfce4 &
保存后赋权:chmod +x ~/.vnc/xstartupgeometry=1280x720
depth=24
systemctl restart vncserver@:1.service。四 防火墙与端口开放
firewall-cmd --zone=public --add-port=5901/tcp --permanent && firewall-cmd --reloadfor p in {1..10}; do firewall-cmd --zone=public --add-port=590${p}/tcp --permanent; done && firewall-cmd --reload五 客户端连接与安全建议
192.168.1.100:1;首次连接输入第 二 步设置的 VNC 密码。ssh -L 5901:localhost:5901 vncuser@服务器IP-localhost(仅本地回环)或使用 -nolisten tcp 禁止直连 TCP;配合 SSH 隧道使用更安全。