TigerVNC
# 安装TigerVNC服务器和密码工具sudo apt updatesudo apt install -y tigervnc-standalone-server tigervnc-tools
# 首次运行需设置密码(会生成~/.vnc/passwd)vncpasswd
# 创建1920x1080分辨率、24位色深的VNC会话(显示端口:1)vncserver :1 -geometry 1920x1080 -depth 24# 启动支持局域网访问的VNC服务# 使用TigerVNC启动,明确指定不限制本地访问Xtigervnc :1 -geometry 1920x1080 -depth 24 -rfbport 5901 -localhost no -SecurityTypes VncAuth -passwordfile ~/.vnc/passwd
# 或使用标准vncserver命令(如已安装完整TigerVNC)vncserver :1 -geometry 1920x1080 -depth 24 -localhost no# 永久配置方案
sudo apt install xfce4 xfce4-goodies -y# 执行之后会有个选项# 建议选择:lightdm
# 1. 创建VNC配置目录mkdir -p ~/.vnc
# 2. 创建正确的xstartup脚本(关键修复)cat > ~/.vnc/xstartup << 'EOF'#!/bin/shunset SESSION_MANAGERunset DBUS_SESSION_BUS_ADDRESSexport XDG_CURRENT_DESKTOP="GNOME"exec gnome-sessionEOF
# # 可选:使用XFCE桌面环境(需安装XFCE组件)# cat > ~/.vnc/xstartup << 'EOF'# #!/bin/sh# unset SESSION_MANAGER# unset DBUS_SESSION_BUS_ADDRESS# exec startxfce4# EOF
# # 可选:使用GNOME桌面环境(需安装GNOME组件)# #!/bin/sh# unset SESSION_MANAGER# unset DBUS_SESSION_BUS_ADDRESS# export XDG_CURRENT_DESKTOP="GNOME"# exec gnome-session
# 3. 添加执行权限chmod +x ~/.vnc/xstartup
# 4. 设置VNC密码(必须步骤)vncpasswd# 输入并确认密码(不会显示输入内容)
# 创建VNC配置文件mkdir -p ~/.vnccat > ~/.vnc/config << 'EOF'geometry=1920x1080depth=24localhost=norfbport=5901EOF
# 设置VNC密码vncpasswd
# 创建systemd服务实现开机自启sudo tee /etc/systemd/system/vncserver@.service << 'EOF'[Unit]Description=TigerVNC Server on %iAfter=syslog.target network.target[Service]Type=forkingUser=pengddGroup=pengddWorkingDirectory=/home/pengddPIDFile=/home/pengdd/.vnc/%H%i.pid # 添加PID文件路径# 修复启动命令,添加-xstartup指定会话脚本ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'ExecStart=/usr/bin/vncserver %i -geometry 1920x1080 -depth 24 -localhost no -xstartup /home/pengdd/.vnc/xstartupExecStop=/usr/bin/vncserver -kill %i[Install]WantedBy=multi-user.targetEOF
# 启用并启动服务sudo systemctl daemon-reloadsudo systemctl enable vncserver@:1sudo systemctl start vncserver@:1# 常用管理命令
# 列出所有VNC会话vncserver -list
# 终止指定会话(:1为显示编号)vncserver -kill :1
# 带日志启动(排障用)vncserver :1 -geometry 1920x1080 -depth 24 -log ~/vncserver.log