这篇文章上次修改于 1518 天前,可能其部分内容已经发生变化,如有疑问可询问作者。

安装

apt update
apt install tightvncserver -y

启动 VNC

初次启动服务,并设置登录密码

vncserver

Password:
Verify:

配置 VNC

停止刚才运行的服务

vncserver -kill

Killing Xtightvnc process ID 17648

备份默认的配置文件

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

创建并编辑配置文件

我这里使用的桌面是 xfce

vim ~/.vnc/xstartup

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

添加执行权限

sudo chmod a+x ~/.vnc/xstartup

启动服务

首次设置 VNC 时,它会在端口 5901 上启动默认服务器实例。该端口称为显示端口,VNC 将其称为:1

VNC 可以在其他显示端口上启动多个实例,如 :2 :3 等等。

vncserver

vncserver -kill  #结束服务
vncserver :1 #对应端口 5901,以此类推

vncserver -kill :1

连接到 VNC 服务

这个就不细讲了

一些问题的解决方法

连接后灰屏

原因是 vncserver 找不到桌面环境

  1. 检查是否安装有桌面环境

    • XFCE 轻量级桌面 apt -y install xfce4 xfce4-goodies
    • mate GNOME2 桌面的分支 apt -y install ubuntu-mate-core ubuntu-mate-desktop
    • Cinnamon GNOME2 桌面的分支 apt -y install cinnamon cinnamon-desktop-environment
    • KDE桌面 apt -y install kubuntu-desktop kde-l10n-zhcn
  2. ~/.vnc/xstartup 权限不对

    • chmod a+x ~/.vnc/xstartup
  3. ~/.vnc/xstartup添加对应的桌面环境配置,将x-window-manager &替换为你使用的桌面环境命令即可

    • startxfce4 & 对应 XFCE
    • mate-session &对应 mate
    • startkde & 对应 KDE
    • gnome-session & 对应 GNOME

补充:Ubuntu Remote Desktop 的使用

安装依赖

sudo apt update && sudo apt install -y vino

将设置中的 Sharing 开关打开,打开 Screen Sharing 并设置一个密码,用于登陆屏幕共享。
Ubuntu推荐使用 remmina 访问屏幕共享。如果你想用 RealVNC 或者 TigerVNC 等访问屏幕共享,最简单的方法是关闭加密,命令如下:

sudo gsettings set org.gnome.Vino require-encryption false

参考

解决配置Ubuntu中vnc远程显示灰屏
解决配置Ubuntu中vnc远程显示灰屏
vncserver灰屏ubuntu 16.04 LTS
Ubuntu下安装配置VNC
用VNC搭建Ubuntu VNC可视化界面
How to Install and Configure VNC on Ubuntu 18.04
Ubuntu Remote Desktop - 18.04 Bionic Beaver Linux
Enable Screen Sharing On Ubuntu 18.04 LTS Desktop Via VNC From Windows Machines