Help Center> Elastic Cloud Server> Best Practices> Using VNC Viewer to Access a Linux ECS
Updated on 2024-03-06 GMT+08:00

Using VNC Viewer to Access a Linux ECS

Linux ECSs are generally accessed through SSH, allowing you to securely log in to your ECSs using key pairs. However, SSH connections use a character-based user interface, which does not support complex operations that are supported on the GUI. This section uses the Ubuntu 20.04 OS as an example to describe how to install VNC Server on a Linux ECS and how to use VNC Viewer to access the ECS.

Preparations

Installing VNC Server

Ubuntu 20.04 has no GUI or VNC Server installed by default. In this example, Xfce, a compact lightweight desktop is used. Xfce is more compact and user-friendly than Gnome and KDE. It applies to remote ECS access.

  1. Remotely log in to the ECS.

    The username is root, and the password is the one you set during ECS creation.

  2. Run the following command to update the software package list:

    sudo apt update

  3. Install Xfce.

    sudo apt install xfce4 xfce4-goodies

  4. Install the TightVNC server.

    sudo apt install tightvncserver

  5. Run the vncserver command to configure the TightVNC server.

    After the first running of the vncserver command, the system automatically creates a default startup script. Then, configure parameters as prompted.

    • Password: consists of 6 to 8 characters. When the number of characters reaches the upper limit (8), no more characters can be entered. Securely keep the password, which will be used by VNC Viewer to access an ECS.
    • Verify: Enter the password again.
    • Would you like to enter a view-only password: If you select y, you are not allowed to use the mouse or keyboard to control your ECS. Press n.

Configuring VNC Server

  1. Stop the first virtual desktop.

    vncserver -kill :1

  2. Modify the xstartup file.

    vim ~/.vnc/xstartup

    Press i to enter insert mode and add the following to the file:

    #!/bin/sh
    xrdb $HOME/.Xresources
    startxfce4 &

    In the preceding terminal display:

    • The first command xrdb $HOME/.Xresources is used to have the VNC GUI framework read the .Xresources file of VNC Server. You can modify GUI settings in the .Xresources file, such as the color display, cursor theme, and font rendering.
    • The second command startxfce4 & have VNC Server start Xfce.

  3. Assign executable permissions to the file to ensure proper VNC running.

    sudo chmod +x ~/.vnc/xstartup

  4. Restart VNC Server.

    vncserver

    After the second running of the vncserver command, the system automatically creates a log file.

    The information similar to "Log file is /root/.vnc/xxx:1.log" is displayed. 1 indicates that the current user is allocated with the first VNC desktop. The VNC port number is "5900+virtual desktop number", which is used by the VNC Viewer agent to access your ECS.

Configuring the ECS on the Management Console

  1. Log in to the management console.
  2. Click the name of your ECS to switch to the page providing details about the ECS.
  3. On the Security Groups tab page, click Modify Security Group Rule to permit port 5901.

    If the log file displayed in the command output of step 4 is xxx:2.log, permit port 5902. If the log file is xxx:3.log, permit port 5903. Apply the rule to other ports.

Using VNC Viewer to Access the ECS

  1. Start the VNC Viewer client on the local computer, enter EIP:5901, set the name, and click OK.

    The port number is determined by the log file name displayed in the command output of step 4. If the log file name is xxx:1.log, enter 5901.

  2. In the displayed dialog box, click Continue.

  3. Enter the password set in step 5 and click OK.

  4. Verify the GUI of the Ubuntu 20.04 OS.