How to install a GUI on Amazon EC2 instance running on Amazon Linux 2?
Hello Readers !!!
Today i am writing this blog regarding to install a graphical user interface (GUI) in my Amazon EC2) instance running Amazon Linux 2.
How do I do this? is there is any other way access GUI ?
Well, yes.
Before Starting, lets launch an instance based on Amazon Linux2.
for that please follow these steps:
step-1 Go to your ec2 services in Amazon management console using search bar, there you will find instance in right corner, click on it
After clicking on it, you will see second image like screen. There click on Launch Instance.
Step-2 Give your instance name as per you want, here I give “ myguiweb”. Then click on Amazon Linux os image and remember instance type must be t2.micro if you do not want to sell your house to pay to amazon.😁
Now scroll down and in “Key pair” section, click on create new pair.
Step-3 Now give your key pair a unique name and select “key pair type” and “private key format” as shown in image. now click on create.
Step-4 Now in “Network Setting” section , select all things as in image. Remeber to all HTTP connection for future references.
That’s it. Easy right….. 😉, then follow me.😁 okk, now on topic..
Click on launch Instance, and our Amazon Linux2 image based os is ready.
Here you can find Public Ip and Private IP of your OS.
Now other main part of our project….
Before proceeding, first consider one of these alternatives to manually installing a GUI:
- Launch from an Amazon Linux 2 AMI that comes with MATE pre-installed.
- Start using Amazon WorkSpaces, a fully managed, persistent desktop virtualization service.
If you have already launched an Instance and want to proceed with manual GUI installation, then do the following:
- Install the MATE desktop environment, a lightweight GUI based on GNOME 2 available as an extra for Amazon Linux 2. see the MATE desktop environment website for more details.
- Install a VNC service like TigerVNC. to download see tigervnc.org website.
- Connect to the GUI using the VNC.
So now we will go for manual GUI installation in Amazon Linux2 image, but remember these steps are apply only to Amazon Linux 2.
Now open Putty software(download form here )and connect with your amazon instance by following steps:
- open putty, enter your instance public ip in Host name and connection type SSH type.
- Now go to Connection > SSH > Auth > Credentials
- Upload your ppk file, which we have download from Amazon in Step-3.
After clicking on Open, you will see a warning message, click on yes. You will see now a window shown below.
To confirm the version that you’re running, run the following command:
grep PRETTY_NAME /etc/os-release
Update your instance by running :
sudo yum update #optional
Now Install the MATE desktop environment
sudo amazon-linux-extras install mate-desktop1.x
Define MATE as your default desktop for all users.
sudo bash -c ‘echo PREFERRED=/usr/bin/mate-session > /etc/sysconfig/desktop’
Install TigerVNC Server:
sudo yum install tigervnc-server
Configure a VNC-specific password, then Restrict VNC network access to the localhost, so that VNC can be accessed only by using a secure SSH tunnel.
After that Create a mandatory configuration file containing the localhost option.
vncpasswd
sudo mkdir /etc/tigervnc #Create the tigervnc configuration directory
sudo bash -c 'echo localhost > /etc/tigervnc/vncserver-config-mandatory'
Start the VNC Server on display number 1, and cause it to always start at boot time. Create a new systemd unit.
sudo cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
Use the sed command to replace all occurrences of USER in the new unit with ec2-user. After that reload the systemd manager configuration.
Turn on the service.
sudo sed -i 's/<USER>/ec2-user/' /etc/systemd/system/vncserver@.service
sudo systemctl daemon-reload
sudo systemctl enable vncserver@:1
Now Insall “tigervnc” software in your local system (for windows) from this link-
After installing this software, close your putty connection from AWS instance, then again open putty software, then —
- Enter your instance public ip in Host name and “connection type” SSH type.
- Now go to Connection > SSH > Tunnel
- in Source port, write 5091 and Destination- “ localhost:5091” then click on add.
- Click on Open.
Now Start the service by following command —
sudo systemctl start vncserver@:1
Now open the tigervnc software on your local system which we have installed previously.
When asked for the VNC server hostname, enter “localhost:1” and then click on connect button.
4. Enter the VNC password that you set up previously.
Here is your GUI running on Amazon Linux2 image.