How To Setup GUI For Amazon EC2 Linux Instance

AWS ec2 linux gui

Amazon ec2 Linux instances do not come with a GUI. By default, you need terminal access for all application configuration. Most of the developers/sysadmins working with Linux would prefer  the command line over Graphical User Interface. But developers who are new to Linux would require a GUI for installing and managing the applications. In this post, we will teach you how to configure a graphical user interface (GUI) for an Amazon ec2 Linux instance.

Setting up GUI for Amazon ec2 Linux (RHEL)

Note: Please follow this tutorial for RHEL7.  Configure GUI on RHEL 7 

Follow the steps given below for setting up a desktop environment for ec2 RHEL6  instance.

1. Login to the instance using any ssh client like putty and update the server.

sudo yum update -y

2. Install the Desktop environment.

sudo yum groupinstall -y "Desktop"
[[email protected]~]# sudo yum groupinstall -y "Desktop"
xulrunner.x86_64 0:17.0.10-1.el6_4zenity.x86_64 0:2.28.0-1.el6
Complete!

3. Install few dependencies using the following command.

sudo yum install -y pixman pixman-devel libXfont
[[email protected]~]$ sudo yum install -y pixman pixman-devel libXfont
Installed:pixman-devel.x86_64 0:0.32.4-4.el6
Complete!

Recommended: Learn Linux in 5 Days and Level Up Your Career Udemy Course

4. Install tiger VNC server.

sudo yum -y install tigervnc-server
[[email protected]~]$ sudo yum -y install tigervnc-server 
xorg-x11-fonts-Type1
Installed: 
tigervnc-server-module.x86_64 0:1.1.0-16.el6
Complete!
[[email protected]~]$

5. Set a password for the default user “ec2-user”

sudo passwd ec2-user
[[email protected]~]$ sudo passwd ec2-user
Changing password for user ec2-user.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected]~]$

6. Set a password for VNC server by executing the following command.

vncpasswd
[[email protected]~]$ vncpasswd
Password:
Verify:
[[email protected]~]$

7. Edit the sshd_config file and set the password authentication parameter to “yes”

8. Restart the sshd service.

sudo service sshd restart
[[email protected]~]$ sudo service sshd restart
Stopping sshd:                                             [ OK ]
Starting sshd:                                             [ OK ]
[[email protected]~]$

9.  Open the vncserver config file.

sudo vi /etc/sysconfig/vncservers

10. Update the parameters of vncserver config file as shown below.

VNCSERVERS="1:ec2-user 2:user2"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1024x768"

Note: You can add more than one user to access vnc server. In the above snippet, we have user2 apart from ec2-user and subsequently make entry for screen resolution for the particular user, as shown above.

11. Start the vnc server

sudo service vncserver start
[[email protected]~]$ sudo service vncserver 
startStarting VNC server: 1:ec2-user 
xauth: creating new authority file /home/ec2-user/.XauthorityNew 'ip-172-29-4-27:1 (ec2-user)'
 desktop is ip-172-29-4-27:1
Creating default startup script /home/ec2-user/.vnc/xstartupStarting applications 
specified in  /home/ec2-user/.vnc/xstartupLog 
file is /home/ec2-user/.vnc/ip-172-29-4-27:1.log                                [ OK ]
[[email protected]~]$

12. Add  vnc service to the system startup so that vnc server will automatically start after a system restart.

sudo chkconfig vncserver on

13. VNC server uses ports starting from 5901. For the second user, the port will be 5902 and so on. In our case, we have only one user (ec2-user). So we will be connecting to the instance on port 5901. Add a firewall rule to your instance to open 5901 using the following command.

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

Note: Open TCP port 5901 in ec2 security group you have assigned to your instance.

14. Now we have an instance with GUI configured. To access it you need a VNC  client. Go to this link to get a VNC viewer client. Install the software and open it.

15. Enter the public IP of you instance followed by the port number 5901 (assuming you the first vnc server user) and click connect. When asked for a password, supply the password you created for vnc server in step 6.

16. Now you will get the access to the GUI. If it asks for ec2-user password, supply the password you created in step 5.

Setting up GUI for ec2 Ubuntu Instance

Check this article for setting up GUI for ec2 Ubuntu instance.

Let us know in the comment section if you face any errors.

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.

8 comments

  1. siv Reply

    i am getting following warning..

    Warning: group Desktop does not exist.
    Maybe run: yum groups mark install (see man yum)
    Error: No packages in any requested group available to install or update
    [[email protected] ~]$
    [[email protected] ~]$

  2. Ravi Chandran Reply

    I followed the above steps exactly. But while connecting the server from windows box with VNC viewer it says “The connection was refused by the host computer”. I have opened the 5901 port in security group as well.

  3. vin Reply

    $ sudo yum groupinstall -y “Desktop”
    Loaded plugins: amazon-id, rhui-lb
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    rhui-REGION-client-config-server-7 | 2.9 kB 00:00
    rhui-REGION-rhel-server-releases | 3.7 kB 00:00
    rhui-REGION-rhel-server-rh-common | 3.8 kB 00:00
    Warning: group Desktop does not exist.
    Maybe run: yum groups mark install (see man yum)
    No packages in any requested group available to install or update

    Do i have to buy this package from the aws console?

  4. Daniel Quintos López Reply

    I have been installed and configured VNC in my EC2 instance, but when I try to connect it with VNC Viewer, it says => “You have exceeded the timeout response”.

    • Daniel Quintos López Reply

      I also enabled the correct port in my security group and ran the vnc service in the instance.

  5. Alex Millan Reply

    Por qué es muy lenta la GUI?, en ocasiones me pasa que hasta se tosca linux y debo reiniciar la instancia. Que otro sistema de vnc recomiendan?, vi la opción de control remoto del sistema, será que mostrará una mejor interfaz?

Leave a Reply

Your email address will not be published. Required fields are marked *