All Products
Document Center

Install and run VNC Server on a Linux instance

Last Updated: Jan 14, 2019

You can use the script provided in this topic to install and run VNC Server on a Linux instance so that you can remotely manage the Linux server in a GUI. Currently, this script applies only to CentOS instances, and automatically installs GNOME Desktop Environment in CentOS instances.

VNC Server Script

Images to which the VNC Server script applies: CentOS only.

Method: Run the bash command as the root user.

Click here to download.


This topic uses the CentOS 7.4 64-bit operating system as an example of how to install and run VNC Server in a Linux instance. This helps you remotely connect to the Linux instance by using VNC Viewer in Windows.


Make sure that your Linux instance is in Running status. For more information, see Start or stop an instance.

Make sure that you have downloaded and installed VNC Viewer in Windows.


To install and run VNC Server on a Linux instance, follow these steps:

  1. Connect the Linux instance remotely. For more information, see Connect to a Linux instance by using a password.

  2. Run the following command to download the script.

    1. wget
  3. Run the script as the root user to install VNC Server.

    1. bash

    It takes several minutes to complete the installation. When the following information is displayed, VNC Server is successfully installed. Record the displayed random password.

    Note: If an error occurs when the script runs, repeat this step until VNC Server is successfully installed.

  4. Run the following command, and then view the port that is used by the Xvnc service in the returned result.

    1. netstat -tulnp

    In this example, the returned result includes the following Xvnc service information:

    1. Active Internet connections (only servers)
    2. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    3. tcp 0 0 LISTEN 1975/Xvnc
    4. tcp 0 0 LISTEN 1975/Xvnc

    The information indicates that VNC Server is using two ports: TCP 5901 and TCP 6001.

    • TCP 5901 allows the VNC client to connect to VNC Server through the RFB protocol. You can use VNC Viewer to connect to the Linux instance through this port.
    • TCP 6001 allows Windows X to connect to VNC Server.
  5. In the security group to which the Linux instance belongs, add security group rules to enable the port required by the Xvnc service.

    In this example, you need to add two security group rules to enable TCP 5901 and TCP 6001 respectively. The following table describes the security group rules.

    Network Type NIC Type Rule Direction Authorization Policy Protocol Type Port Range Authorization Type Authorization Object Priority
    VPC No required Inbound Allow Custom TCP 5901/5901 and 6001/6001 Address field access 1
    Classic Internet
  6. If the Linux instance has enabled a firewall, add security group rules to enable the ports. For more information, see the user manual of the corresponding firewall.

    This topic uses iptables as an example. You can run the following commands to add security group rules and enable TCP 5901 and TCP 6001:

    1. [root@iZXXXZ ~]# iptables -A INPUT -p tcp dport 5901 -j ACCEPT
    2. [root@iZXXXZ ~]# iptables -A INPUT -p tcp dport 6001 -j ACCEPT
    3. [root@iZXXXZ ~]# service iptables save
  7. Use VNC Viewer in Windows to connect to the Linux instance by following these steps:

    1. Start VNC Viewer in Windows.

    2. From the menu bar, select File > New Connection.

    3. In the Properties dialog box, set the following parameters, and then click OK.

      • VNC Server: Enter the Internet IP address of the Linux instance: 5901.
      • Name: Enter a connection name as needed.

    4. In the VNC Viewer window, right-click the connection icon, and then click Connect from the shortcut menu.

    5. In the Authentication dialog box, enter the password that you recorded after VNC Server is installed in step 3, and then click OK.

      Note: The password used here is not the logon password of the Linux instance.

You have successfully log on to the Linux instance.


What should I do if the system indicates that I’m trying to run as the root super user when I log on to the CentOS 6 instance for the first time?

This is not an error message. Follow these steps:

  1. Select Do not show me this again.
  2. Click Close.