s-blog

CentOS 安装部署 VNC 远程服务

ssssmy · 2026-06-05 · 2 min · CentOS

安装

# 检查是否已安装 vnc
rpm -qa | grep vnc
# 安装 vnc 服务
yum -y install vnc vnc-server
yum -y install tightvnc-server

首次启动并设置密码

vncserver   # 首次启动会提示设置密码(至少 6 位),需记住,远程时使用

配置防火墙

firewall-cmd --zone=public --add-port=5901/tcp --permanent
firewall-cmd --zone=public --add-port=6001/tcp --permanent

配置桌面客户端

vi /root/.vnc/xstartup

末尾添加:

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
gnome-session &

编辑 vim /etc/sysconfig/vncservers(或 /lib/systemd/system/[email protected]),添加:VNCSERVERS="1:root"(不修改则远程看不到桌面)。

依赖 GNOME 桌面

# 查看是否安装 GNOME
yum grouplist
# 安装 GNOME 桌面
yum groupinstall "GNOME Desktop"

服务管理

vncserver -kill :1     # 关闭
vncserver :1           # 重启
vncserver -list        # 查看启动的桌面数

客户端用 VNC Viewer 连接,格式为 ip地址:桌面号(如 <服务器IP>:5901)。

原文链接:https://www.ssssmy.com/notes/centos-an-zhuang-bu-shu-vnc-yuan-cheng-fu-wu