Help Center/ Elastic Cloud Server/ Best Practices/ Connecting to a Linux ECS Using VNC Viewer
Updated on 2026-07-29 GMT+08:00

Connecting to a Linux ECS Using VNC Viewer

Linux ECSs are generally connected through SSH, enabling secure, passwordless login through key pairs. SSH connections generally use a character-based user interface (CLI), but sometimes a graphical interface (GUI) is required for more complex operations. This section describes how to install VNC Server on an ECS running Ubuntu and how to use VNC Viewer to connect to the ECS.

Prerequisites

Step 1: Install VNC Server

In this example, Xfce, a compact lightweight desktop, is used. Xfce is more compact and user-friendly than GNOME and KDE. It is suitable for remote connection.

  1. Remotely log in to the ECS.

    The username is root, and the password is the one you set during ECS creation. For details, see Login Overview (Linux).

  2. Run the following command to update the software list:
    sudo apt update
  3. Run the following command to install the Xfce desktop environment:
    sudo apt install xfce4 xfce4-goodies
  4. Run the following command to install the TightVNC server:
    sudo apt install tightvncserver
  5. Run the vncserver command.

    When you run vncserver for the first time, a default startup script is created automatically. Configure the parameters as follows.

    • Password: Enter a password containing 6 to 8 characters. Passwords longer than 8 characters will be automatically truncated, with only the first eight characters used as the VNC login password. Securely keep the password. You will use it when connecting to the ECS using VNC Viewer.
    • Verify: Enter the password again.
    • Would you like to enter a view-only password (y/n)?: Press n. Users logging in with a view-only password will not be able to control the cloud server with the mouse or keyboard.

Step 2: Configure VNC Server

  1. Run the following command to stop the first virtual desktop:
    vncserver -kill :1

  2. Run the following command to modify the xstartup file:
    vim ~/.vnc/xstartup

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

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

    Note:

    • xrdb $HOME/.Xresources: instructs the VNC GUI framework to read the .Xresources file of VNC Server. In this file, you can modify certain graphical desktop settings, such as the color display, cursor themes, and font rendering.
    • startxfce4 &: instructs the server to start Xfce.

  3. To ensure that the VNC service can start properly, run the following command to make the file executable:
    sudo chmod +x ~/.vnc/xstartup
  4. Run the following command to restart VNC Server:
    vncserver

    When you run vncserver for the second time, a log file is created automatically.

    Information similar to "Log file is /root/.vnc/xxx:1.log" is displayed in the command output. 1 indicates that the current user is assigned the first VNC virtual desktop.

Step 3: Configure Security Group Rules on the ECS Console

  1. Log in to the ECS console and access the ECS list page.
  2. Click the target ECS name to go to the ECS details page.
  3. On the Security Groups tab, click Manage Rule on the right of the target security group.
  4. On the Inbound Rules tab, click Add Rule.
  5. Add an inbound rule to allow traffic on port 5901.
    Figure 1 Modifying security group rules

Step 4: Connect to the ECS Using VNC Viewer

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

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

  2. In the displayed dialog box, click Continue.

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

  4. After the connection is established, view the Ubuntu GUI. To open a terminal on the Ubuntu GUI, right-click Open Terminal Here.
    Figure 2 Ubuntu 20.04 GUI
    Figure 3 Ubuntu 24.04 GUI

FAQs

  • Why can't I access the GUI through VNC Viewer?

    Symptom: An error message shown in the following figure is displayed when you attempt to access the GUI through VNC Viewer.

    Solution:

    • Check whether port 5901 required by the VNC service is opened in the firewall of the Ubuntu server. For details, see Why Am I Unable to Connect to a Port on an ECS?
    • Check whether the firewall is configured on the local PC.
    • Check whether the EIP of the Ubuntu server can be pinged from the local PC.

    For details, see Why Can't I Log In to My Linux ECS?

  • How do I reset the VNC password?
    1. Change the VNC password. Enter a new password as prompted and confirm it.
      vncpasswd
      The password must contain 6 to 8 characters. Passwords longer than 8 characters will be automatically truncated, with only the first eight characters used as the VNC login password.
    2. (Optional) Restart the VNC service.
      vncserver -kill :1
      vncserver