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
- An ECS running Ubuntu 16.04/18.04/20.04/22.04/24.04 has been created and an EIP has been bound to it for public network access. For details, see Purchasing an ECS in Custom Config Mode and Assigning an EIP.
- The rules listed in the following table have been added to the security groups that the target ECS belongs to. For details, see Adding a Security Group Rule.
Table 1 Security group rules Direction
Priority
Action
Type
Protocol & Port
Source
Inbound
1
Allow
IPv4
TCP: 5901
0.0.0.0/0
- The VNC Viewer client has been installed on a local PC.
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.
- 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).
- Run the following command to update the software list:
sudo apt update
- Run the following command to install the Xfce desktop environment:
sudo apt install xfce4 xfce4-goodies
- Run the following command to install the TightVNC server:
sudo apt install tightvncserver
- 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
- Run the following command to stop the first virtual desktop:
vncserver -kill :1

- 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.

- To ensure that the VNC service can start properly, run the following command to make the file executable:
sudo chmod +x ~/.vnc/xstartup
- 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
- Log in to the ECS console and access the ECS list page.
- Click the target ECS name to go to the ECS details page.
- On the Security Groups tab, click Manage Rule on the right of the target security group.
- On the Inbound Rules tab, click Add Rule.
- 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
- 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.

- In the displayed dialog box, click Continue.

- Enter the password set in 5 and click OK.

- 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?
- 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. - (Optional) Restart the VNC service.
vncserver -kill :1 vncserver
- Change the VNC password. Enter a new password as prompted and confirm it.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot