在 Ubuntu 上通过 VNC 实现远程桌面,通常步骤如下(以最常用的 TightVNC / TigerVNC + GNOME 桌面 为例,也适用于 Xfce)。
sudo apt update
sudo apt install ubuntu-desktop
# 或轻量桌面
sudo apt install xfce4 xfce4-goodies
sudo apt install tightvncserver
sudo apt install tigervnc-standalone-server tigervnc-common
vncserver
首次运行会:
~/.vnc编辑 ~/.vnc/xstartup:
nano ~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
export XKL_XMODMAP_DISABLE=1
session=gnome-session
#!/bin/bash
startxfce4 &
保存后赋予权限:
chmod +x ~/.vnc/xstartup
vncserver :1 -geometry 1280x720 -depth 24
:1 → 端口 5901:2 → 端口 5902查看运行状态:
vncserver -list
在本地 VNC 客户端中连接:
UbuntuIP:5901
输入设置的 VNC 密码即可。
sudo nano /etc/systemd/system/vncserver@.service
内容示例:
[Unit]
Description=VNC Server
After=network.target
[Service]
Type=forking
User=youruser
ExecStart=/usr/bin/vncserver :1
ExecStop=/usr/bin/vncserver -kill :1
[Install]
WantedBy=multi-user.target
启用:
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1
✅ 不要直接暴露 5901 到公网 ✅ 使用 SSH 隧道:
ssh -L 5901:localhost:5901 user@ubuntu_ip
本地连接:
localhost:5901
❌ 灰屏 → xstartup 配置错误
❌ 无法连接 → 防火墙未放行或 VNC 未启动
❌ 卡顿 → 降低分辨率或改用 Xfce
如果你告诉我:
我可以给你更精确的配置方案。