在 CentOS(7/8/Stream) 上开启 VNC 的常用做法如下,适用于 远程桌面访问。
下面以 TigerVNC 为例,逐步说明。
yum install -y tigervnc-server
dnf install -y tigervnc-server
切换到要开启 VNC 的用户(如 root 或普通用户):
vncpasswd
会生成
~/.vnc/passwd
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
编辑:
vi /etc/systemd/system/vncserver@:1.service
找到:
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
修改为你的用户名,例如:
ExecStart=/usr/bin/vncserver_wrapper root %i
或普通用户:
ExecStart=/usr/bin/vncserver_wrapper myuser %i
systemctl daemon-reload
systemctl start vncserver@:1
systemctl enable vncserver@:1
查看状态:
systemctl status vncserver@:1
VNC 默认端口:
:1 → 5901:2 → 5902firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload
如果连接失败,可临时关闭 SELinux 测试:
setenforce 0
永久关闭(可选,不推荐生产环境):
vi /etc/selinux/config
SELINUX=disabled
服务器IP:1
或
服务器IP:5901
确保安装了桌面环境:
yum groupinstall "GNOME Desktop" -y
ss -lntp | grep 590
✅ 不要直接暴露 VNC 到公网
✅ 使用 SSH 隧道:
ssh -L 5901:localhost:5901 user@服务器IP
然后连接:
localhost:1
如果你告诉我 CentOS 具体版本 + 是否需要 root 桌面,我可以给你更精确的配置方案。