教程长篇分享

在 Ubuntu 22.04 上安装和配置 VNC 远程桌面

环境

Step-1 安装桌面环境

Ubuntu 默认使用 GNOME 桌面环境,但也可以安装其他桌面环境,如 Xfce、KDE 等。这个可以根据个人喜好选择,之前尝试了 Xfce 好像效果不是很好,这里直接安装 Ubuntu 默认的桌面环境了。

更新软件源。

sudo apt update

安装桌面环境所需的软件包,包括系统面板、窗口管理器、文件浏览器、终端等桌面应用程序。

sudo apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop

Step-2 安装 VNC

安装 TightVNC 服务器。

sudo apt install tightvncserver

Step-3 配置 VNC

初始化配置

通过 vncserver 命令启动 VNC 服务器实例,第一次运行时同时会完成初始化(设置 VNC 访问密码,创建初始配置文件)。

vncserver

系统将提示输入并验证密码以远程访问您的机器:

OutputYou will require a password to access your desktops.

Password:
Verify:

密码的长度必须介于六到八个字符之间。超过 8 个字符的密码将被自动截断。

验证密码后,可以选择创建仅供查看的密码。使用仅查看密码登录的用户将无法使用鼠标或键盘控制 VNC 实例,没有演示需要的输入 n 即可,后续如有需要可以再设置。

OutputWould you like to enter a view-only password (y/n)? 

然后会在端口上启动一个默认服务器实例5901。此端口称为显示端口,VNC 将其称为:1. VNC 可以在其他显示端口上启动多个实例,:2对应端口5902:3对应5903

后续如果想更改密码或添加仅查看密码,可以使用以下命令:

vncpasswd

配置 xstartup 配置文件

在配置 xstartup 配置文件时,可以使用不同的窗口管理器和桌面环境。本教程使用的是 GNOME Flashback 桌面环境和 metacity 窗口管理器。如果希望使用其他的桌面环境和窗口管理器,需要相应地修改 xstartup 配置文件。

备份VNC的xstartup配置文件。

cp ~/.vnc/xstartup ~/.vnc/xstartup.bak

修改VNC的xstartup配置文件。

nano ~/.vnc/xstartup

复制以下内容到文件:

#!/bin/sh
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME"
export XDG_MENU_PREFIX="gnome-flashback-"
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check

这里网上最后都有一个 &,原本用来在后台执行脚本的,但是最新的 vncserver 不需要这个,有了这个反而可能报错 Session startup via '/root/.vnc/xstartup' cleanly exited too early ( :1` 指定显示端口号

重新启动 VNC。

vncserver -geometry 1920x1080 :1 -localhost no

geometry 选项指定窗口大小,localhost 选项设为 no 以开放连接。

Step-4 连接到 VNC

用你喜欢的客户端连接到 VNC 服务器,我这里用的是 RealVNC 的 VNC Viewer。

在下面输入对应的 IP:端口 回车即可连接。

image-20230328163843782

参考

  1. 通过VNC搭建Ubuntu 18.04和20.04图形界面, https://help.aliyun.com/document_detail/59330.html
  2. New VNC install - 'cleanly exited too early', https://ubuntuforums.org/showthread.php?t=2470276

本文链接: https://linuxstory.org/how-to-install-and-configure-vnc-on-ubuntu-22-04

LinuxStory 原创教程,转载请注明出处,否则必究相关责任。欢迎来操作系统论坛 https://zhos.net 访问交流与提问。

对这篇文章感觉如何?

太棒了
12
不错
3
爱死了
3
不太好
3
感觉很糟
3

You may also like

13 Comments

  1. Supplier Sinar Baja Medan – Toko BESI H BEAM Terlengkap di medan, Toko
    BESI UNP / CNP Terlengkap di medan, Jual PLAT HAIR LINE
    Terlengkap dikota medan , Toko BESI POLOS Terlengkap
    dikota medan – Sinar Baja

  2. Supplier Sinar Baja Medan – Agen BESI COIL Terbaik di
    medan, Toko BESI SIKU Terlengkap dikota medan, Agen BESI
    HOLLOW Terlengkap dikota medan ,Jual PLAT HAIR LINE Terbaik dikota medan – Sinar Baja

  3. Supplier Sinar Baja Medan – Harga BESI EXPANDED Terbaik
    di medan, Jual BESI POLOS Termurah di medan, Toko BESI H BEAM
    Terlengkap dikota medan , Supplier PLAT RAIL
    Terlengkap di medan – Sinar Baja

  4. Supplier Sinar Baja Medan – Toko BESI UNP / CNP
    Terlengkap dikota medan, Jual BESI COIL Terlengkap dikota medan, Harga PIPA
    BAJA Terlengkap dikota medan , Agen PIPA BESI Terpercaya di medan – Sinar Baja

  5. Supplier Sinar Baja Medan – Harga BESI SIKU Terlengkap di medan, Distributor BESI POLOS Termurah
    di medan, Harga PLAT BORDER Terlengkap di
    medan , Harga PIPA BESI Terbaik dikota medan – Sinar Baja

  6. Supplier Sinar Baja Medan – Toko PLAT BAJA Terlengkap dikota medan, Harga PLAT KUNINGAN
    Termurah di medan, Supplier PLAT HAIR LINE Termurah dikota medan , Distributor BESI POLOS
    Termurah dikota medan – Sinar Baja

  7. Supplier Sinar Baja Medan – Jual PLAT BESI Terlengkap
    dikota medan, Harga BESI WF Termurah dikota medan, Jual
    BESI UNP / CNP Terlengkap dikota medan , Supplier BESI H BEAM
    Terpercaya di medan – Sinar Baja

  8. Supplier Sinar Baja Medan – Harga BESI ULIR Terbaik di medan,
    Jual BESI H BEAM Termurah dikota medan, Agen
    PLAT RAIL Terlengkap di medan ,Jual PLAT BORDER Termurah di medan – Sinar Baja

  9. First off I want to say excellent blog! I had a quick question that I’d like to ask if you don’t mind. I was curious to know how you center yourself and clear your mind before writing. I have had trouble clearing my mind in getting my thoughts out. I truly do enjoy writing however it just seems like the first 10 to 15 minutes are generally wasted simply just trying to figure out how to begin. Any recommendations or tips? Many thanks!

  10. You’ve made some decent points there. I checked on the net for additional information about the issue and found most individuals will go along with your views on this website.

  11. vncserver -geometry 1920×1080 :1 -localhost no最后这条命令我用的连接不了,

    我之前在其他地方试过vncserver -geometry 1920×1080 :1这样能连接的,就是黑屏,但是那个教程黑屏

    我跟着这边教程在这边最后修改为上面这样试了一下,成功连接,没有黑屏

  12. 无法连接呀

Leave a reply

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

More in:教程

教程

PuTTY 使用综合指南:SSH 连接 Linux

无论您是经验丰富的开发人员还是初学者,想在您的计算机和远程 Linux 服务器之间建立安全连接,PuTTY 是一个值得信赖的工具。让我们深入了解如何在 Windows 操作系统上利用 PuTTY 进行 […]
教程

在 Ubuntu 像22.04 LTS Linux 安装 JUnit 5

JUnit 不仅简单而且是一种有效的方法来编写和执行 Java 应用程序的单元测试,因此它是开源类别中使用最广泛的测试框架。 JUnit的最新版本5发布时带来了许多改进。 所以,如果你使用Ubuntu […]
教程

同时运行多个 Linux 命令

了解如何在 Linux 中同时执行多个命令可以显著提高您的效率和生产力。本文将指导您通过各种方式在单行中运行多个 Linux 命令,甚至如何自动化重复的任务。 理解基础知识 在深入了解高级技巧之前,您 […]