温馨提示×

Ubuntu VNC怎么启动

小樊
40
2026-08-11 15:33:06
栏目: 智能运维

在 Ubuntu 上启动 VNC 的方式取决于你用的是 桌面版还是服务器版,下面给你几种最常见、最实用的方法,从简单到完整。


一、最常用方式(推荐):TigerVNC + GNOME(Ubuntu 桌面版)

1️⃣ 安装桌面环境(如果没有)

sudo apt update
sudo apt install ubuntu-desktop gnome-shell

2️⃣ 安装 TigerVNC

sudo apt install tigervnc-standalone-server tigervnc-common

3️⃣ 设置 VNC 密码

vncpasswd

4️⃣ 启动 VNC Server

vncserver :1 -geometry 1920x1080 -depth 24
  • :1 → 端口是 5901
  • :2 → 5902,以此类推

5️⃣ 连接 VNC

在客户端使用:

IP:5901

二、Ubuntu Server(无桌面)推荐方式

1️⃣ 安装轻量桌面 + VNC

sudo apt install xfce4 xfce4-goodies tigervnc-standalone-server

2️⃣ 配置 VNC

vncserver
vncserver -kill :1

编辑配置文件:

nano ~/.vnc/xstartup

内容改为:

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4

赋予执行权限:

chmod +x ~/.vnc/xstartup

3️⃣ 启动

vncserver :1

三、使用 systemd(开机自启,推荐服务器)

创建服务

sudo nano /etc/systemd/system/vncserver@.service

内容(替换 youruser):

[Unit]
Description=VNC Server
After=network.target

[Service]
Type=forking
User=youruser
ExecStart=/usr/bin/vncserver :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

启动

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

四、常见问题排查

✅ 黑屏

  • 检查 ~/.vnc/xstartup
  • 确认桌面环境已安装

✅ 连接被拒绝

ss -lntp | grep 590

✅ 防火墙

sudo ufw allow 5901/tcp

五、客户端推荐

  • Windows / macOS:RealVNC Viewer
  • Linux:Remmina
  • Android:VNC Viewer

如果你愿意,可以告诉我:

  • ✅ Ubuntu 版本(20.04 / 22.04 / 24.04)
  • ✅ 桌面版还是服务器版
  • ✅ 是否要 远程桌面像 Windows RDP 一样

我可以给你最合适的一套配置方案

0