Ubuntu下TigerVNC使用教程汇总
打开终端,依次执行以下命令更新系统软件包列表并安装TigerVNC核心组件:
sudo apt update
sudo apt install tigervnc-standalone-server tigervnc-common
部分教程提到也可通过Snap包管理器安装(适用于Ubuntu 18.04及以上版本):
sudo apt install snapd
sudo snap install core
sudo snap install tigervnc
运行vncpasswd命令,按照提示输入并确认密码(密码长度需至少6位)。此密码用于后续VNC客户端连接时的身份验证。
TigerVNC启动时需通过~/.vnc/xstartup文件指定桌面环境(如GNOME、Xfce),否则可能出现黑屏、灰屏或无状态栏等问题。
vncserver会自动创建):nano ~/.vnc/xstartup#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
gnome-session & # 启动GNOME桌面
若使用Xfce桌面(轻量级,推荐用于老旧设备),将最后一行改为:startxfce4 &chmod +x ~/.vnc/xstartupvncserver命令启动,后面可跟显示编号(如:1对应端口5901、:2对应5902)。示例:vncserver :1 -geometry 1920x1080 -depth 24-geometry设置分辨率,-depth设置颜色深度(推荐24位)。vncserver -kill :1(将:1替换为目标显示编号)为避免每次重启服务器都需手动启动VNC,可创建Systemd服务文件:
sudo nano /etc/systemd/system/vncserver@.serviceyour_username替换为实际用户名):[Unit]
Description=Start TigerVNC server at startup
After=multi-user.target
[Service]
Type=forking
User=your_username
Group=your_username
PAMName=login
PIDFile=/home/your_username/.vnc/%H%i.pid
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver :%i -geometry 1280x800 -depth 24
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reloadsudo systemctl enable vncserver@1.service(:1为显示编号)sudo systemctl start vncserver@1.service若Ubuntu启用了UFW防火墙,需允许VNC端口(默认5901对应显示编号:1,5902对应:2)的流量:
sudo ufw allow 5901/tcp
sudo ufw enable(若未启用防火墙)
192.168.1.100:1),点击连接后输入步骤2中设置的密码。ssh -L 5901:localhost:5901 your_username@your_server_iplocalhost:5901~/.vnc/xstartup文件是否包含正确的桌面环境启动命令(如gnome-session &或startxfce4 &),并确保文件有执行权限。netstat -ntupl | grep vnc),防火墙是否允许端口,或尝试添加-localhost no参数允许远程连接(如vncserver -geometry 1920x1080 :1 -localhost no)。xstartup文件中添加x-window-manager &或xfwm4 &(针对Xfce桌面)以启动窗口管理器。