By default, an AWS EC2 instance running Amazon Linux 2 OS does not come with a GUI. However, you can enable GUI in AWS EC2 instance by following the below steps –
Step 1: Connect to your EC2 instance.
Step 2: Check your OS name
1 2 3 |
cat /etc/os-release ## Confirm your OS is Amazon Linux 2, in the output PRETTY_NAME="Amazon Linux 2" ## The method described in this demo is applicable to AMazon Linux 2 OS only. |
Step 3: Update your EC2 instance packages
1 |
sudo yum update -y |
Step 4: Install MATE packages.
1 |
sudo amazon-linux-extras install mate-desktop1.x |
Step 5: Define MATE as your default desktop.
1 2 3 4 5 |
## For all users: sudo bash -c 'echo PREFERRED=/usr/bin/mate-session > /etc/sysconfig/desktop' ## For current user (ec2-user): echo "/usr/bin/mate-session" > ~/.Xclients && chmod +x ~/.Xclients |
Step 6: Install TigerVNC packages:
1 |
sudo yum install tigervnc-server |
Step 7: Configure a VNC-specific password containing 6 to 8 characters for this user.
1 2 3 4 |
vncpasswd ## When asked if you want to enter a view-only password, press "n". ## Note the password in a safe place, it will be required later to connect to your instance. |
Step 8: Start the VNC Server on display number 1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## 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. sudo sed -i 's/ ## Reload the systemd manager configuration. sudo systemctl daemon-reload ## Enable the service. sudo systemctl enable vncserver@:1 ## Start the service. sudo systemctl start vncserver@:1 |
Step 9: Download and install the TigerVNC software on your local computer using the below link
https://tigervnc.org/
Step 10: On your local computer, use SSH to connect to your instance while creating a tunnel to forward all traffic on local port 5901/TCP (VNC) to the instance’s VNC server:
1 2 3 |
## Replace PEM_FILE with the path for your private key. ## Replace INSTANCE_IP with your instance's public or private IP ssh -L 5901:localhost:5901 -i PEM_FILE ec2-user@INSTANCE_IP |
Step 11: Open the VNC Client on your local computer. When asked for the VNC server hostname, enter localhost:1 and then connect to it.
Step 12: Enter the VNC password you set up in step 2 of the Install TigerVNC section. If an alert appears stating that the connection isn’t secure, disregard it.