温馨提示×

centos vnc怎么远程

小樊
44
2026-09-11 15:50:58
栏目: 智能运维

在 CentOS 上通过 VNC 远程桌面,通常步骤如下(以 CentOS 7/8 为例,CentOS 6 类似但服务名不同):


一、服务端配置(被控的 CentOS)

1. 安装桌面环境(如果还没装)

# CentOS 7
yum groupinstall "GNOME Desktop" -y

# CentOS 8
dnf groupinstall "Server with GUI" -y

2. 安装 VNC 服务

yum install tigervnc-server -y

3. 设置 VNC 密码

vncpasswd

(输入远程登录密码)

4. 配置 VNC 服务

复制模板:

cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service

编辑:

vi /etc/systemd/system/vncserver@:1.service

修改 <USER> 为你的用户名,例如 root 或普通用户:

ExecStart=/usr/bin/vncserver_wrapper <USER> %i

5. 启动 VNC 服务

systemctl daemon-reload
systemctl enable vncserver@:1
systemctl start vncserver@:1

默认端口:5901(:1)


二、防火墙放行

firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload

如果是云服务器,还要在 安全组 放行 5901。


三、客户端连接(你的电脑)

Windows

使用 VNC Viewer

  • 地址:服务器IP:5901
  • 输入密码

Linux

vncviewer 服务器IP:5901

macOS

使用 RealVNC Viewer 或 Screen Sharing


四、常见问题

1. 黑屏 / 无法显示桌面

编辑:

vi ~/.vnc/xstartup

加入:

unset SESSION_MANAGER
exec gnome-session &

然后重启 VNC:

vncserver -kill :1
vncserver :1

2. 想用 root 远程

不推荐,但可行,注意安全风险。

3. 更安全的方式(推荐)

通过 SSH 隧道:

ssh -L 5901:localhost:5901 user@服务器IP

本地连接 127.0.0.1:5901


如果你告诉我:

  • CentOS 版本(6/7/8)
  • 是否云服务器
  • 用 root 还是普通用户

我可以给你更精确的一步到位命令。

0 踩