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中

相关推荐
远游客07132 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
马甲是掉不了一点的<.<2 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
jingyu飞鸟2 小时前
centos-stream9系统安装docker
linux·docker·centos
超爱吃士力架3 小时前
邀请逻辑
java·linux·后端
White_Mountain3 小时前
在Ubuntu中配置mysql,并允许外部访问数据库
数据库·mysql·ubuntu
LIKEYYLL4 小时前
GNU Octave:特性、使用案例、工具箱、环境与界面
服务器·gnu
云云3215 小时前
搭建云手机平台的技术要求?
服务器·线性代数·安全·智能手机·矩阵
云云3215 小时前
云手机有哪些用途?云手机选择推荐
服务器·线性代数·安全·智能手机·矩阵
cominglately5 小时前
centos单机部署seata
linux·运维·centos
魏 无羡5 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos