All Products
Search
Document Center

How do I install VNC Server on a Linux instance to implement GUI-based access

Last Updated: May 31, 2019

Due to performance and universal compatibility considerations, the Virtual Network Computing (VNC) Server programs are not installed in the Alibaba Cloud public Linux images by default. To access a Linux instance through a GUI, you need to install VNC Server and a GUI on the instance.

This topic describes how to install VNC Server in CentOS 6.8, CentOS 7.2, and Ubuntu 14.04 to access a Linux instance through a GUI.

Note: If you selected the CentOS image for your instance, you can use a script to automatically install VNC Server and GNOME desktop. For more information, see Automatic installation of VNC Server on Linux instances.

Prerequisites

You have installed a VNC Server connection tool, for example, TightVNC Java Viewer, on your local server.

Install VNC Server in CentOS 6.8

This section describes how to install TigerVNC Server and GNOME in CentOS 6.8.

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

  2. Run the following command to install the GNOME desktop:

    1. yum groupinstall GNOME Desktop Environment -y

    The installation might take a few minutes.

  3. Run the following command to install VNC Server:

    1. yum install -y tigervnc-server
  4. Run the following command to enable the automatic startup mode for VNC Server:

    1. chkconfig --level 345 vncserver on
  5. Run the following command to start VNC Server and set the connection password as prompted:

    1. vncserver

    Note: You need to set the connection password when you start VNC Server for the first time. You can change the password later by running the vncpasswd command.

  6. Follow these steps to modify the /root/.vnc/xstartup file and set the GNOME desktop:

    1. Run the vim /root/.vnc/xstartup command.
    2. Press i.
    3. In the last line of the file, comment out twm & and add a line of gnome-session &.
    4. Press Esc, enter :wq, and save the settings.
  7. Follow these steps to configure the listening port and environment parameters in the /etc/sysconfig/vncservers file:

    1. Run the vim /etc/sysconfig/vncservers command.
    2. Press i.
    3. Add the following content:
      1. VNCSERVERS="1:root"
      2. VNCSERVERARGS[1]="-geometry 1200x800"
    4. Press Esc, enter :wq, and save the settings.
  8. (Optional) Complete other settings by running the subsequent commands.

    • Run the following command to grant the GUI access permission to the root account:
      1. sed -i 's/.!= root./#&/' /etc/pam.d/gdm
    • If the following errors are reported, run the dbus-uuidgen >/var/lib/dbus/machine-id command to generate a new machine ID.
      1. D-Bus library appears to be incorrectly set up; failed to read
      2. machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
    • The SELinux and NetworkManager services cannot be enabled on ECS. If you have enabled these services, run the following commands to modify the settings:
      1. vi /etc/selinux/config # Check whether the value of SELINUX is disabled. If no, change the value to disabled.
      2. chkconfig --del NetworkManager # Disable the NetworkManager service.
  9. Run the following command to restart VNC Server:

    1. service vncserver restart
  10. Run the ps -ef | grep vnc command to check whether VNC Server has started. If the following information is displayed, VNC Server has started.

    CentOS6.8_result of ps command

    As shown in the preceding figure (outlined in red), TCP port 5901 is used.

  11. (Optional) If you have enabled a firewall on your instance, you need to grant the TCP port 5901 access permission to VNC Server.

    Example: If you want iptables to allow VNC Server to access TCP port 5901, run the following commands:

    1. iptables -A INPUT -p tcp --dport 5901 -j ACCEPT # Enable TCP port 5901.
    2. service iptables save # Save the rule.
  12. Log on to the ECS console, add a security group rule to the group where your instance is located, and enable TCP port 5901. For more information about how to add a security group rule, see Add security group rules.

  13. Connect to an instance on the local VNC Viewer. For more information, see Automatic installation of VNC Server on Linux instances. If the following GUI is displayed, VNC Server is successfully installed and GUI-based access can be implemented.

    CentOS6.8_use VNC Server to access GNOME desktop

Install VNC Server in CentOS 7.2

This section describes how to install TigerVNC Server and GNOME in CentOS 7.2.

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

  2. Run the following command to install the GNOME desktop:

    1. yum groupinstall GNOME Desktop Environment -y

    The installation might take a few minutes.

  3. Run the following command to install VNC Server:

    1. yum install tigervnc-server -y
  4. Follow these steps to modify the VNC Server configuration file and set the root user name:

    1. Run the vim /lib/systemd/system/vncserver@.service command.
    2. Press i.
    3. Replace the content in User=<User>, ExecStart, and PIDFile with the following content:

      1. User=root
      2. # Clean any existing files in /tmp/.X11-unix environment
      3. ExecStartPre=-/usr/bin/vncserver -kill %i
      4. ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
      5. PIDFile=/root/.vnc/%H%i.pid

      CentOS7.2_modify configuration file

    4. Press Esc, enter :wq, and save the settings.

  5. Run the following command to change /lib/systemd/system/vncserver@.service to /lib/systemd/system/vncserver@:1.service:

    1. mv /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
  6. Run the following command to restart systemd:

    1. systemctl daemon-reload
  7. Run the vncpasswd command and set the connection password as prompted.

  8. (Optional) The SELinux and NetworkManager services cannot be enabled on ECS. If you have enabled these services, run the following commands to modify the settings:

    1. vi /etc/selinux/config # Check whether the value of SELINUX is disabled. If no, change the value to disabled.
    2. chkconfig --del NetworkManager # Disable the NetworkManager service.
  9. Run the following command to enable the automatic startup mode for VNC Server:

    1. systemctl enable vncserver@:1.service
  10. Run the following command to start VNC Server:

    1. systemctl start vncserver@:1.service
  11. Run the ps -ef | grep vnc command to check whether VNC Server has started. If the following information is displayed, VNC Server has started.

    CentOS7.2_result of ps command

    As shown in the in the preceding figure (outlined in red), TCP port 5901 is used.

  12. (Optional) If you have enabled a firewall on your instance, you need to grant the TCP port 5901 access permission to VNC Server.

    Example: If you want firewalld to allow VNC Server to access TCP port 5901, run the following commands:

    1. firewall-cmd --permanent --add-service vnc-server # Allow VNC Server to access TCP port 5901.
    2. systemctl restart firewalld.service # Restart firewalld.
  13. Log on to the ECS console, add a security group rule to the group where your instance is located, and enable TCP port 5901. For more information about how to add a security group rule, see Add security group rules.

  14. Connect to an instance on the local VNC Viewer. For more information, see Automatic installation of VNC Server on Linux instances. If the following GUI is displayed, VNC Server is successfully installed and GUI-based access can be implemented.

    CentOS7.2_use VNC Server to access GNOME desktop

Install VNC Server in Ubuntu 14.04

This section describes how to install vnc4server and GNOME in Ubuntu 14.04.

  1. Connect to a Linux instance. For more information, see Connect to a Linux instance by using a password.
  2. Run the apt-get update command to update the source list.
  3. Run the following command to install vnc4server:

    1. apt-get install vnc4server -y
  4. Run the following command to start VNC Server and set the connection password as prompted:

    1. vnc4server

    Note: You need to set the connection password when you start VNC Server for the first time. You can change the password later by running the vncpasswd command.

    As shown in the following figure, if the information such as New ':1 (root)' desktop is :1 (host name) is displayed, vnc4server has successfully started. A .vnc directory will be automatically generated under the home directory of the root user.

    Ubuntu_start vnc4server

  5. Run the ps -ef | grep vnc command to check whether vnc4server has started. If the following information is displayed, vnc4server has started.

    Ubuntu_result of ps command

    As shown in the in the preceding figure (outlined in red), TCP port 5901 is used.

  6. Run the following command to install the GNOME desktop:

    1. apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

    The installation might take a few minutes.

  7. (Optional) Run the following command to back up the existing xstartup file:

    1. cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
  8. Follow these steps to modify the startup file of vnc4server:

    1. Run the following command to open the file:
      1. vim ~/.vnc/xstartup
    2. Press i.
    3. Replace the content in the file with the following content:
      1. #!/bin/sh
      2. # Uncomment the following two lines for normal desktop:
      3. # unset SESSION_MANAGER
      4. # exec /etc/X11/xinit/xinitrc
      5. [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
      6. [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
      7. xsetroot -solid grey
      8. vncconfig -iconic &
      9. #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
      10. #x-window-manager &
      11. gnome-panel &
      12. gnome-settings-daemon &
      13. metacity &
      14. nautilus &
      15. gnome-terminal &
    4. Press Esc, enter :wq, and save the settings.
  9. Run the following commands to generate a new session:

    1. vncserver -kill :1 # Kill the existing desktop process (assume that the desktop No. is :1).
    2. vncserver :1 # Generate a new session.
  10. Log on to the ECS console, add a security group rule to the group where your instance is located, and enable TCP port 5901. For more information about how to add a security group rule, see Add security group rules.

  11. Connect to an instance on the local VNC Viewer. For more information, see Automatic installation of VNC Server on Linux instances. If the following GUI is displayed, VNC Server is successfully installed and GUI-based access can be implemented.

    Ubuntu_use VNC Server to access GNOME desktop

If you have additional questions about how to install VNC Server on a Linux instance to implement GUI-based access, visit our Alibaba Cloud Community portal for further advice and discussions, or seek additional support from our sellers on the Alibaba Cloud Marketplace.