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.
Images to which the VNC Server script applies: CentOS only.
Method: Run the bash install_vnc_server.sh 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:
Connect the Linux instance remotely. For more information, see Connect to a Linux instance by using a password.
Run the following command to download the install_vnc_server.sh script.
Run the script as the root user to install VNC Server.
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.
Run the following command, and then view the port that is used by the Xvnc service in the returned result.
In this example, the returned result includes the following Xvnc service information:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5901 0.0.0.0: LISTEN 1975/Xvnc
tcp 0 0 0.0.0.0:6001 0.0.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.
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 0.0.0.0/0 1 Classic Internet
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:
[root@iZXXXZ ~]# iptables -A INPUT -p tcp —dport 5901 -j ACCEPT
[root@iZXXXZ ~]# iptables -A INPUT -p tcp —dport 6001 -j ACCEPT
[root@iZXXXZ ~]# service iptables save
Use VNC Viewer in Windows to connect to the Linux instance by following these steps:
Start VNC Viewer in Windows.
From the menu bar, select File > New Connection.
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.
In the VNC Viewer window, right-click the connection icon, and then click Connect from the shortcut menu.
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:
- Select Do not show me this again.
- Click Close.