在 Ubuntu 上配置 VNC(Virtual Network Computing)通常有几种方案:TightVNC / TigerVNC + 桌面环境 或 x11vnc(共享当前桌面)。下面给你一套最常用、最稳妥的 Ubuntu VNC 配置教程(以 TigerVNC + Xfce 为例,轻量且稳定)。
sudo apt update
sudo apt upgrade -y
推荐轻量桌面:
sudo apt install xfce4 xfce4-goodies -y
sudo apt install tigervnc-standalone-server tigervnc-common -y
vncpasswd
密码保存在 ~/.vnc/passwd
nano ~/.vnc/xstartup
写入以下内容:
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
赋予执行权限:
chmod +x ~/.vnc/xstartup
vncserver :1 -geometry 1280x720 -depth 24
查看运行状态:
vncserver -list
停止:
vncserver -kill :1
sudo ufw allow 5901/tcp
使用:
连接地址:
服务器IP:5901
输入之前设置的 VNC 密码即可。
sudo nano /etc/systemd/system/vncserver@.service
内容(替换 username):
[Unit]
Description=VNC Server
After=syslog.target network.target
[Service]
Type=forking
User=username
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
sudo systemctl start vncserver@1
~/.vnc/xstartupssh -L 5901:localhost:5901 user@server
然后连接 localhost:5901
如果你告诉我:
我可以给你更精确的配置示例。