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中

相关推荐
嚯——哈哈6 分钟前
AWS云服务器:开启高效计算的新纪元
服务器·云计算·aws
嚯——哈哈7 分钟前
从入门到精通:解析如何使用亚马逊云服务器(AWS EC2)
运维·服务器·aws
编程修仙40 分钟前
Collections工具类
linux·windows·python
芝麻团坚果1 小时前
对subprocess启动的子进程使用VSCode python debugger
linux·ide·python·subprocess·vscode debugger
写点什么啦1 小时前
[debug]不同的window连接ubuntu的vscode后无法正常加载kernel
linux·vscode·ubuntu·debug
wellnw1 小时前
[ubuntu]编译共享内存读取出现read.c:(.text+0x1a): undefined reference to `shm_open‘问题解决方案
linux·ubuntu
不爱学习的YY酱1 小时前
【操作系统不挂科】<CPU调度(13)>选择题(带答案与解析)
java·linux·前端·算法·操作系统
DC_BLOG1 小时前
Linux-Nginx虚拟主机
linux·运维·nginx
XY.散人2 小时前
初识Linux · 信号处理 · 续
linux·信号处理
1900432 小时前
linux复习5:C prog
linux·运维·服务器