Linux simple application servers provide only CLIs. If you want to use a GUI to manage an operating system, you can use Virtual Network Console (VNC) to build a GUI. This topic describes how to build a GUI on Ubuntu.

Prerequisites

  • A simple application server that runs an Ubuntu operating system is created. For more information, see Create a server.
  • Rules are added to the firewall of the Ubuntu server to allow traffic from ports 5900 and 5901. These ports are required for the VNC service. For more information, see Add a firewall rule.

Background information

This topic describes how to use VNC to build a GUI on Ubuntu 18.04 and Ubuntu 20.04. This topic also shows how to use VNC Viewer to connect to the GUI from an on-premises Windows machine. If you want to use VNC to build a GUI on Ubuntu 16.04, see Use VNC to build GUIs on Ubuntu 16.04.

Step 1: Build a GUI

  1. Connect to the Ubuntu server.
  2. Run the following command to switch to the root user:
    sudo su root
  3. Install the software package.
    1. Run the following command to update the software repository:
      apt-get update
    2. Run the following command to install the software package that is required by the desktop environment:
      The software package includes desktop applications such as system panels, window managers, file browsers, and terminals.
      apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop
      When you install the software package, the system displays the following message. Enter y and press Enter. 125Follow the on-screen instructions to install the software package.
  4. Configure VNC.
    1. Install VNC.
      • Ubuntu 18.04: Run the following command to install VNC.
        apt-get install vnc4server
        When you install the software package, the system displays the following message. Enter y, and press Enter.1258
      • Ubuntu 20.04: Run the following command to install VNC.
        apt-get install tightvncserver
    2. Run the following command to start VNC:
      vncserver
      The first time you use VNC, you must set the VNC logon password, enter the password, and then confirm the password. You must enter n as prompted, and press Enter. 2558
      Notice The logon password of VNC can be up to 8 characters in length. If the specified string exceeds eight characters in length, VNC uses the first eight characters of the string as the password.
      If the command output includes the information that is provided in the red box as shown in the following figure, VNC is started. Start VNC

      izbp166dsac66tx****:1 indicates the port number of the VNC that is started on the server. izbp166dsac66tx**** is the host name.

    3. Run the following command to back up the xstartup configuration file of VNC:
      cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
    4. Run the following command to modify the xstartup configuration file of VNC:
      vi ~/.vnc/xstartup
    5. Press the i key to enter the edit mode and modify the configuration file to the following content:
      #!/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 &
    6. Press the Esc key, enter :wq, and then press the Enter key to save and close the file.
  5. Restart VNC.
    1. Run the following command to close the active VNC session:
      vncserver -kill :1
    2. Run the following command to start a new VNC session.
      The display ID of the new VNC session remains as 1.
      vncserver -geometry 1920x1080 :1

Step 2: Use VNC Viewer to connect to the Ubuntu server

  1. Download and install VNC Viewer on your computer.
    Visit the official VNC website to obtain the download link and installation instructions for VNC Viewer.
  2. Start VNC Viewer. In the top navigation bar, choose File > New connection...
    VNC Viewer
  3. In the Properties dialog box, configure the logon information of the Ubuntu desktop and click OK.
    You must configure the following parameters:
  4. Double-click the card of the Ubuntu desktop.
    In this example, double-click the card whose Ubuntu desktop name is test001.
  5. In the Authentication dialog box, enter the password of the VNC in the Password field and click OK.
    password
    After you log on to the VNC server, the Ubuntu GUI is displayed, as shown in the following figure. If you need to open the terminal in the Ubuntu GUI, right-click Open Terminal in the Ubuntu GUI. 2588If you cannot use the VNC Viewer tool to log on to the VNC server, make sure that you configure the 5900 and 5901 ports that are required for VNC in the firewall of the Ubuntu server. For more information, see Add a firewall rule. 2358