远程访问 Ubuntu 上的 VNC,一般步骤是:在 Ubuntu 上安装并配置 VNC 服务 → 设置远程访问方式(直接 / 通过 SSH 隧道)→ 在本地使用 VNC 客户端连接。下面给你一套常用且稳妥的方案。
sudo apt update
sudo apt upgrade -y
sudo apt install ubuntu-desktop -y
# 或轻量一些
sudo apt install xfce4 xfce4-goodies -y
sudo apt install tigervnc-standalone-server tigervnc-common -y
vncpasswd
(密码用于 VNC 连接)
mkdir -p ~/.vnc
nano ~/.vnc/xstartup
示例(XFCE):
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
赋予执行权限:
chmod +x ~/.vnc/xstartup
vncserver :1 -geometry 1920x1080 -depth 24
:1 → 端口 5901:2 → 端口 5902查看运行状态:
vncserver -list
停止:
vncserver -kill :1
ssh -L 5901:localhost:5901 user@ubuntu_ip
5901localhost:5901然后使用 VNC 客户端连接:
localhost:5901
✅ 优点:加密、安全、不需要开放 VNC 端口
Ubuntu 防火墙:
sudo ufw allow 5901/tcp
VNC 客户端直接填:
ubuntu_ip: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
~/.vnc/xstartup如果你告诉我:
我可以给你更精确的一步到位配置方案。