如何在Ubuntu 20.04上使用X2Go设置远程桌面

The author selected Software in the Public Interest (SPI) to receive a donation as part of the Write for DOnations program.

作者选择了公益软件(SPI)来接受捐赠,这是Write for DOnations计划的一部分。

介绍 (Introduction)

Usually, Linux-based servers don’t come with a graphical user interface (GUI) pre-installed. Whenever you want to run GUI applications on your instance, the typical solution is to employ Virtual Network Computing (VNC). Unfortunately, VNC solutions can be sluggish and insecure; many also require a lot of manual configuration. By contrast, X2Go provides a working “cloud desktop,” complete with all the advantages of an always-online, remotely-accessible, and easily-scalable computing system with a fast network. It is also more responsive and more secure than many VNC solutions.

通常,基于Linux的服务器没有预先安装图形用户界面(GUI)。 每当您想在实例上运行GUI应用程序时,典型的解决方案就是采用虚拟网络计算(VNC)。 不幸的是,VNC解决方案可能很迟钝且不安全。 许多还需要大量的手动配置。 相比之下, X2Go提供了一个工作的“云桌面”,并具有始终在线,可远程访问且易于扩展且具有快速网络的计算系统的所有优点。 与许多VNC解决方案相比,它还具有更高的响应速度和安全性。

In this tutorial, you’ll use X2Go to create an Ubuntu 20.04 XFCE desktop environment that you can access remotely. This cloud desktop will include the same utilities that you would obtain had you installed Ubuntu 20.04 and the XFCE environment on your personal computer (almost identical to a Xubuntu setup).

在本教程中,您将使用X2Go创建可远程访问的Ubuntu 20.04 XFCE桌面环境。 该云桌面将包含与在个人计算机上安装Ubuntu 20.04和XFCE环境(与Xubuntu设置几乎相同)时所获得的相同的实用程序。

The setup described in this tutorial is useful when:

本教程中描述的设置在以下情况下很有用:

  • You need access to a Linux-based operating system, complete with a desktop environment, but can’t install it on your personal computer.

    您需要访问基于Linux的操作系统,该操作系统具有桌面环境,但是不能将其安装在您的个人计算机上。
  • You use multiple devices in multiple locations and want a consistent work environment with the same tools, look, files, and performance.

    您在多个位置使用多个设备,并希望使用相同的工具,外观,文件和性能来提供一致的工作环境。
  • Your Internet service provider gives you very little bandwidth, but you need access to tens or hundreds of gigabytes of data.

    您的Internet服务提供商为您提供的带宽很少,但是您需要访问数十或数百GB的数据。
  • Long-running jobs make your local computer unavailable for hours or days. Imagine that you have to compile a large project, which will take 8 hours on your laptop. You won’t be able to watch movies or do anything else very resource-intensive while your project compiles. But if you run that job on your server, now your computer is free to perform other tasks.

    长时间运行的作业使您的本地计算机无法使用数小时或数天。 想象一下,您必须编译一个大型项目,这将在您的笔记本电脑上花费8个小时。 在项目编译时,您将无法观看电影或执行其他任何占用大量资源的操作。 但是,如果您在服务器上运行该作业,则您的计算机现在可以自由执行其他任务。
  • You’re working with a team, and it benefits them to have a shared computer that they can access to collaborate on a project.

    您正在与团队合作,他们拥有一台共享的计算机可以供他们在项目上进行协作,这对他们有利。

先决条件 (Prerequisites)

Before starting this tutorial, you’ll need:

在开始本教程之前,您需要:

  • An Ubuntu 20.04 x64 instance with 2GB of RAM or more. 2GB is minimal, but a server with 4GB or more is ideal if you have memory-hungry applications that you plan to run. You can use a DigitalOcean Droplet if you like.

    具有2GB或更多RAM的Ubuntu 20.04 x64实例。 2GB的内存是最小的,但是如果您打算运行需要大量内存的应用程序,那么4GB或更大的服务器是理想的选择。 如果愿意,可以使用DigitalOcean Droplet 。

  • A user with sudo privileges and an SSH key. Follow this guide to get started: Initial Server Setup with Ubuntu 20.04. Make sure you complete Step 4 and configure your firewall to restrict all connections except for OpenSSH.

    具有sudo特权和SSH密钥的用户。 请遵循本指南进行入门: 使用Ubuntu 20.04进行初始服务器设置 。 确保完成步骤4并将防火墙配置为限制除OpenSSH以外的所有连接。

第1步-在服务器上安装桌面环境 (Step 1 — Installing the Desktop Environment on Your Server)

With your server up and your firewall configured, you are now ready to install the graphical environment for the X2Go server.

在服务器启动并配置了防火墙之后,现在可以为X2Go服务器安装图形环境了。

First, update the package manager’s information about the latest software available:

首先,更新有关最新可用软件的程序包管理器信息:

  • sudo apt-get update

    sudo apt-get更新

In this tutorial, you are installing XFCE as the desktop environment. XFCE doesn’t use graphical effects like compositing, making it more compatible with X2Go and optimizing screen updates. For reference, the LXDE desktop environment and the MATE desktop environment (with compositing disabled) also work fine, but you’ll have to change the command in this tutorial where you install the desktop environment. For example, instead of sudo apt-get install xubuntu-desktop, you would type sudo apt-get install lubuntu-desktop to install LXDE.

在本教程中,您将XFCE安装为桌面环境。 XFCE不使用图形效果,例如合成,使其与X2Go更加兼容并优化屏幕更新。 作为参考, LXDE桌面环境和MATE桌面环境 (禁用了合成)也可以正常工作,但是您必须在安装桌面环境的本教程中更改命令。 例如,您可以键入sudo apt-get install lubuntu -desktop来安装LXDE ,而不是sudo apt-get install xubuntu-desktop

There are two ways to install XFCE; the Minimal Desktop Environment or the Full Desktop Environment. The best choice for you will depend on your needs, which we will cover next. Choose one of the two.

有两种安装XFCE的方法: 最小桌面环境或完整桌面环境。 您的最佳选择取决于您的需求,我们将在下文中介绍。 选择两者之一

完整的桌面环境 (The Full Desktop Environment)

Recommended for most use cases. If you don’t want to handpick every component you need and would rather have a default set of packages, like a word processor, web browser, email client, and other accessories pre-installed, you can choose xubuntu-desktop.

建议用于大多数用例。 如果您不想手动选择所需的每个组件,而是希望预先安装一套默认的软件包,例如字处理器,Web浏览器,电子邮件客户端和其他附件,则可以选择xubuntu-desktop

Install and configure the Full Desktop Environment. The Full Desktop Environment is similar to what you would get if you installed Xubuntu from a bootable DVD/USB memory stick to your local PC:

安装和配置完整桌面环境。 完整桌面环境类似于从可启动DVD / USB记忆棒到本地PC上安装Xubuntu的情况:

  • sudo apt-get install xubuntu-desktop

    sudo apt-get install xubuntu-desktop

When prompted to choose a display manager, pick lightdm.

当提示您选择显示管理器时,选择lightdm

最小的桌面环境 (The Minimal Desktop Environment)

Alternately, if you want to install a small, core set of packages and then build on top of them by manually adding whatever you need, you can use the xubuntu-core meta-package.

或者,如果您要安装一组小的核心程序包,然后通过手动添加所需的内容在它们之上构建,则可以使用xubuntu-core元程序包。

A meta-package doesn’t contain a single package; instead, a meta-package includes an entire package collection. Installing a meta-package saves the user from manually installing numerous components.

元软件包不包含单个软件包。 相反,元包包括整个包集合。 安装元软件包可以使用户免于手动安装大量组件的麻烦。

Install xfce4 and all of the additional dependencies needed to support it:

安装xfce4以及支持它的所有其他依赖项:

  • sudo apt-get install xubuntu-core

    须藤apt-get install xubuntu-core

You have installed a graphical environment. Now you will establish a way to view it remotely.

您已经安装了图形环境。 现在,您将建立一种远程查看方式。

第2步-在服务器上安装X2Go (Step 2 — Installing X2Go on the Server)

X2Go comes with two main components: the server, which starts and manages the graphical session on the remote machine, and the client, which you install on your local computer to view and control the remote desktop or application.

X2Go包含两个主要组件:服务器(用于启动和管理远程计算机上的图形会话),以及客户端(您可以将其安装在本地计算机上以查看和控制远程桌面或应用程序)。

In previous versions of Ubuntu (before 18.04), x2goserver wasn’t included in the default repositories, so you’d have to follow steps like these to get the software package. We’re leaving the link here, just for reference, in case the package gets dropped in future versions of Ubuntu. Fortunately, Ubuntu 20.04, codenamed Focal Fossa, includes the package you need in its default repositories, so the installation is faster.

在Ubuntu的x2goserver版本(18.04之前的版本)中,默认存储库中未包含x2goserver ,因此您必须遵循以下步骤来获取软件包 。 我们将在此保留链接,以供参考,以防软件包在将来的Ubuntu版本中丢失。 幸运的是,代号为Focal Fossa的Ubuntu 20.04在其默认存储库中包含了您需要的软件包,因此安装速度更快。

To install X2Go on your server, type the following command:

要在服务器上安装X2Go,请键入以下命令:

  • sudo apt-get install x2goserver x2goserver-xsession

    sudo apt-get install x2goserver x2goserver-xsession

At this point, your server requires no further setup. However, keep in mind that if you followed the recommendation of setting up SSH keys in the Initial Server Setup with Ubuntu 20.04, then you will need to have your SSH private key available on every local machine that you intend to use. If you didn’t set up an SSH private key, make sure you choose a strong password.

此时,您的服务器不需要进一步设置。 但是,请记住,如果遵循在Ubuntu 20.04的“ 初始服务器设置”中设置SSH密钥的建议,那么您将需要在打算使用的每台本地计算机上使用SSH私钥。 如果未设置SSH私钥,请确保选择一个强密码。

Note: Remember that if you run out of RAM, the Linux kernel might abruptly terminate some applications, resulting in lost work. If you are using a DigitalOcean Droplet and you notice that your programs require more RAM, you can temporarily power off your Droplet and upgrade (resize) to one with more memory.

注意:请记住,如果RAM用完了,Linux内核可能会突然终止某些应用程序,从而导致工作丢失。 如果您使用的是DigitalOcean Droplet,并且您注意到程序需要更多的RAM,则可以暂时关闭Droplet的电源并升级(调整大小)为具有更多内存的磁盘 。

You have configured your server. Type exit or close your terminal window. The rest of the steps will focus on configuring the client on your local machine.

您已经配置了服务器。 输入exit或关闭您的终端窗口。 其余步骤将重点放在在本地计算机上配置客户端。

步骤3 —在本地安装X2Go客户端 (Step 3 — Installing the X2Go Client Locally)

X2Go is ready to use out of the box. If you’re using Windows or Mac OS X on your local machine, you can download the X2Go client software here. If you’re using Debian or Ubuntu you can install the X2Go client with this command on your local machine:

X2Go可以立即使用。 如果您在本地计算机上使用Windows或Mac OS X,则可以在此处下载X2Go客户端软件 。 如果您使用的是Debian或Ubuntu,则可以使用以下命令在本地计算机上安装X2Go客户端:

  • sudo apt-get install x2goclient

    sudo apt-get install x2goclient

After downloading the software, you are ready to install it. Open the installer and select your preferred language. Now agree to the license and let the wizard guide you through the remaining steps. Typically, there shouldn’t be any reason to change the pre-filled, default values in these steps.

下载软件后,您就可以安装它了。 打开安装程序,然后选择您的首选语言。 现在,同意许可,然后让向导引导您完成其余步骤。 通常,在这些步骤中应该没有任何理由更改预填充的默认值。

X2Go works well out of the box, but it is also highly customizable. If you’d like additional information, visit X2Go’s official documentation.

X2Go开箱即用,但高度可定制。 如果您需要其他信息,请访问X2Go的官方文档 。

Now that you have installed the desktop client, you can configure its settings and connect to the X2Go server to use your remote XFCE desktop.

现在,您已经安装了桌面客户端,可以配置其设置并连接到X2Go服务器以使用远程XFCE桌面。

步骤4 —连接到远程桌面 (Step 4 — Connecting To the Remote Desktop)

When you first open the X2Go client, a window will appear. If it doesn’t, click Session in the top-left menu and then select New session ….

首次打开X2Go客户端时,将出现一个窗口。 如果不是这样,单击会话在左上角的菜单,然后选择新建会话...。

In the Session name field, enter something to help differentiate between servers. Using a session name is particularly useful if you plan on connecting to multiple machines.

在“ 会话名称”字段中,输入一些内容以帮助区分服务器。 如果您打算连接到多台计算机,则使用会话名称特别有用。

Enter your server’s IP address or a fully qualified domain name (FQDN) in the Host field under Server.

输入服务器的IP地址或完全限定域名(FQDN)根据服务器主机领域。

Enter the username you used for your SSH connection in the Login field.

登录字段中输入用于SSH连接的用户名。

Since you installed XFCE in Step Two, choose XFCE as your Session type.

由于您在第二步中安装了XFCE,因此请选择XFCE作为您的会话类型

Finally, because you connect to the server with SSH keys, click the folder icon next to Use RSA/DSA key for ssh connection and browse to your private key. If you didn’t opt to use the more secure SSH keys, leave this empty; the X2Go client will ask for a password each time you log in.

最后,由于您使用SSH密钥连接到服务器,因此请单击“ 使用RSA / DSA密钥进行ssh连接”旁边的文件夹图标,然后浏览至私钥。 如果您不选择使用更安全的SSH密钥,请将其留空; 每次登录时,X2Go客户端都会要求输入密码。

The rest of the default settings will suffice for now, but as you get more familiar with the software, you can fine-tune the client based on your individual preferences.

其余的默认设置现在就足够了,但是随着您对软件的熟悉程度的提高,您可以根据个人喜好微调客户端。

After pressing the OK button, you can start your graphical session by clicking the white box that includes your session’s name on the box’s top-right side.

按下“ 确定”按钮后,您可以通过单击右上角包含会话名称的白框来启动图形会话。

If you are running OS X on your local machine, OS X might prompt you to install XQuartz, which is required to run X11. If so, follow the instructions to install it now.

如果您在本地计算机上运行OS X,则OS X可能会提示您安装XQuartz ,这是运行X11所必需的。 如果是这样,请按照说明立即安装。

In a few seconds, your remote desktop will appear, and you can start interacting with it.

几秒钟后,您的远程桌面将出现,您可以开始与其进行交互。

There are a few useful keyboard shortcuts you can use for a better experience on Windows and Linux-based operating systems.

您可以使用一些有用的键盘快捷键来在基于Windows和Linux的操作系统上获得更好的体验。

Note: These first two options can exhibit buggy behavior on modern Windows editions. You can still test them at this point, in case later versions of X2Go fix the issues. If they fail, just avoid using the same keyboard shortcut in the future.

注意:前两个选项可能会在现代Windows版本上显示错误行为。 如果更高版本的X2Go可以解决问题,您仍然可以在此时进行测试。 如果它们失败了,那就避免以后再使用相同的键盘快捷键。

CTRL+ALT+F will toggle full-screen mode on and off. Working in full-screen mode can feel more like a local desktop experience. The full-screen mode also helps the remote machine grab keyboard shortcuts instead of your local machine.

CTRL+ALT+F将打开和关闭全屏模式。 在全屏模式下工作更像是本地桌面体验。 全屏模式还可以帮助远程计算机代替本地计算机来获取键盘快捷键。

CTRL+ALT+M will minimize the remote view, even if you are in full-screen mode.

即使您处于全屏模式, CTRL+ALT+M也会最小化远程视图。

CTRL+ALT+T will disconnect from the session but leave the GUI running on the server. It’s just a quick way of disconnecting without logging off or closing applications on the server. The same will happen if you click the window’s close button.

CTRL+ALT+T将断开会话连接,但GUI在服务器上运行。 这只是断开连接而无需注销或关闭服务器上的应用程序的快速方法。 如果您单击窗口的关闭按钮,也会发生同样的情况。

Lastly, there are two ways you can end the remote session and close all of the graphical programs running in it. You can log off remotely from XFCE’s start menu, or you can click the button marked with a circle and a small line (like a power/standby icon) in the bottom-right corner of the main portion of the X2Go screen.

最后,您可以通过两种方式结束远程会话并关闭其中运行的所有图形程序。 您可以从XFCE的“ 开始”菜单中远程注销,也可以单击X2Go屏幕主要部分右下角带有圆圈和小线(如电源/待机图标)的按钮。

The first method is cleaner but may leave programs like session-managing software running. The second method will close everything but may do so forcefully if a process can’t exit cleanly. In either case, be sure to save your work before proceeding.

第一种方法比较干净,但是可能会使诸如会话管理软件之类的程序运行。 第二种方法将关闭所有内容,但是如果进程无法干净退出,则可以强制执行此操作。 无论哪种情况,请务必先保存您的工作,然后再继续。

You have now successfully accessed and configured your remote desktop.

现在,您已经成功访问​​并配置了远程桌面。

结论 (Conclusion)

In this tutorial, you used X2Go to create a robust and remote GUI-environment for the Ubuntu operating system. Now that you are up and running, here are a few ideas about using this desktop:

在本教程中,您使用X2Go为Ubuntu操作系统创建了一个健壮的远程GUI环境。 现在您已经启动并正在运行,以下是有关使用此桌面的一些想法:

  • You could centralize your development work by creating a git repository.

    您可以通过创建git存储库来集中开发工作 。

  • You could install an IDE/code editor like NetBeans or Eclipse. You could also use Visual Studio Code for remote development via the Remote-SSH Plugin.

    您可以安装IDE /代码编辑器,例如NetBeans或Eclipse。 您还可以使用Visual Studio Code通过Remote-SSH Plugin进行远程开发 。

  • You could configure a web server for testing web applications.

    您可以配置Web服务器以测试Web应用程序。

  • You could also enhance your remote desktop with a good backup scheme to preserve your work environment and essential data in case something ever goes wrong. With DigitalOcean, you can also snapshot your Droplets when you’re happy with a particular setup. This way, you can test risky changes and always come back to a known, working state.

    您还可以通过良好的备份方案来增强远程桌面,以保留工作环境和必要的数据,以防万一出问题。 使用DigitalOcean,您还可以在对特定设置感到满意时对Droplet进行快照 。 这样,您可以测试危险的更改并始终返回已知的工作状态。

If you’d like to learn more, visit X2Go’s official documentation website.

如果您想了解更多信息,请访问X2Go的官方文档网站 。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-remote-desktop-with-x2go-on-ubuntu-20-04

你可能感兴趣的:(python,linux,java,大数据,数据库)