Ubuntu 22 安装VNC远程图形界面(GNOME)

0.更新软件源

bash 复制代码
$ sudo apt update

1.安装VNC

bash 复制代码
$ sudo apt install tightvncserver

2.安装GNOME

bash 复制代码
$ sudo apt install -y gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop

3. 安装支持VNC与Windows之间复制粘贴

bash 复制代码
$ sudo apt install xclip autocutsel

4.VNC配置

4.1 首次运行设置密码

bash 复制代码
$ vncserver

4.2 修改配置文件

bash 复制代码
$ vi ~/.vnc/xstartup

直接复制如下内容,覆盖原文件内容

bash 复制代码
$ cat ~/.vnc/xstartup
#!/bin/sh

xsetroot -solid grey
autocutsel -fork

XAUTHORITY=$HOME/.Xauthority
export XAUTHORITY

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME"
export XDG_MENU_PREFIX="gnome-flashback-"
export QT_STYLE_OVERRIDE=""
export FONTCONFIG_PATH=/etc/fonts
export FONTCONFIG_FILE=/etc/fonts/fonts.conf


gnome-session --session=gnome-flashback-metacity --disable-acceleration-check

4.3 添加启动关闭脚本

或者直接直接运行启动关闭命令

bash 复制代码
$ cat ~/vncserver_start.sh
vncserver -geometry 1920x1080 :1

$ cat ~/vncserver_stop.sh
vncserver -kill :1

5.VNC Viewer访问

下载并安装VNCViewer:
Download VNC Viewer - free - latest version

VNC Viewer访问IP:5901

6.常见问题解决

6.1 VNC 与 Windows不能自由复制粘贴

解决办法:安装上述 3 的软件包,并增加配置autocutsel -fork到xstartup

6.2 VNC中不能打开firefox,chrome等图形软件

命令打开firefox报错

bash 复制代码
$ firefox&
client is not authorized to connect server. Error cannot open display: :1

图形打开chrome也报错:

bash 复制代码
$ tail -f ~/.vnc/test:1.log
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding 24
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding 15
18/02/24 02:59:49 Using hextile encoding for client IP
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding 16
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding 22
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding 21
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding -314
18/02/24 02:59:49 Enabling full-color cursor updates for client IP
18/02/24 02:59:49 rfbProcessClientNormalMessage: ignoring unknown encoding -223
AUDIT: Sun Feb 18 03:00:05 2024: 9115 Xtightvnc: client 19 rejected from local host
AUDIT: Sun Feb 18 03:01:21 2024: 9115 Xtightvnc: client 19 rejected from local host
AUDIT: Sun Feb 18 03:01:39 2024: 9115 Xtightvnc: client 19 rejected from local host

报错:

bash 复制代码
# tail -f /var/log/syslog
Feb 18 05:14:12 test metacity.desktop[16840]: Xlib:  extension "X-Resource" missing on display ":1".
Feb 18 05:14:13 test metacity.desktop[16840]: Xlib:  extension "X-Resource" missing on display ":1".
Feb 18 05:14:14 test update-notifier.desktop[18750]: Error executing command as another user: Not authorized
Feb 18 05:14:14 test update-notifier.desktop[18750]: This incident has been reported.
Feb 18 05:14:17 test metacity.desktop[16840]: Xlib:  extension "X-Resource" missing on display ":1".
Feb 18 05:14:18 test systemd[1731]: Started snap.chromium.chromium-78740d23-4cba-42a3-abaa-23bd8d66c8ed.scope.
Feb 18 05:14:19 test kernel: [11200.212683] kauditd_printk_skb: 27 callbacks suppressed
Feb 18 05:14:19 test kernel: [11200.212690] audit: type=1326 audit(1708233259.395:210): auid=1000 uid=1000 gid=1000 ses=2 subj=snap.chromium.chromium pid=18923 comm="chrome" exe="/snap/chromium/2757/usr/lib/chromium-browser/chrome" sig=0 arch=c000003e syscall=330 compat=0 ip=0x7f27c51d3f6b code=0x50000
Feb 18 05:14:19 test kernel: [11200.212703] audit: type=1326 audit(1708233259.395:211): auid=1000 uid=1000 gid=1000 ses=2 subj=snap.chromium.chromium pid=18922 comm="chrome" exe="/snap/chromium/2757/usr/lib/chromium-browser/chrome" sig=0 arch=c000003e syscall=330 compat=0 ip=0x7f7ebf741f6b code=0x50000
Feb 18 05:14:19 test chromium_chromium.desktop[18753]: Client is not authorized to connect to Server[18753:18753:0218/051419.723825:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
Feb 18 05:14:19 test chromium_chromium.desktop[18753]: [18753:18753:0218/051419.723881:ERROR:env.cc(257)] The platform failed to initialize.  Exiting.

解决办法:在启动vncserver之前,加上环境变量

bash 复制代码
$ XAUTHORITY=$HOME/.Xauthority
$ export XAUTHORITY

$ env | grep XAUTHORITY
XAUTHORITY=/home/xxx/.Xauthority

也可以直接命令行执行,或者加到~/.bashrc中

相关推荐
乙己4073 小时前
计算机网络——网络层
运维·服务器·计算机网络
飞行的俊哥3 小时前
Linux 内核学习 3b - 和copilot 讨论pci设备的物理地址在内核空间和用户空间映射到虚拟地址的区别
linux·驱动开发·copilot
hunter2062065 小时前
ubuntu向一个pc主机通过web发送数据,pc端通过工具直接查看收到的数据
linux·前端·ubuntu
qzhqbb5 小时前
web服务器 网站部署的架构
服务器·前端·架构
不会飞的小龙人6 小时前
Docker Compose创建镜像服务
linux·运维·docker·容器·镜像
不会飞的小龙人6 小时前
Docker基础安装与使用
linux·运维·docker·容器
张3蜂6 小时前
docker Ubuntu实战
数据库·ubuntu·docker
白粥行7 小时前
linux-ubuntu学习笔记碎记
linux·ubuntu
果果开发ggdoc.cn7 小时前
WordPress免费证书插件
服务器·https·ssl
jerry-897 小时前
通过配置核查,CentOS操作系统当前无多余的、过期的账户;但CentOS操作系统存在共享账户r***t
linux