- How do I install a GUI on my Amazon EC2 instance running Amazon Linux 2?
- Short description
- Resolution
- Before you begin
- Install the MATE desktop environment
- Install TigerVNC
- Connect to the GUI using the VNC
- (Optional) Install a web browser
- Connect to your Linux instance using SSH
- Prerequisites
- Connect to your Linux instance using an SSH client
- Transfer files to Linux instances using an SCP client
- Troubleshoot
- Tutorial: Get started with Amazon EC2 Linux instances
- Overview
- Prerequisites
- Step 1: Launch an instance
- Step 2: Connect to your instance
- Step 3: Clean up your instance
- Next steps
How do I install a GUI on my Amazon EC2 instance running Amazon Linux 2?
Last updated: 2021-04-20
I want to install a graphical user interface (GUI) in my Amazon Elastic Compute Cloud (Amazon EC2) instance running Amazon Linux 2. How do I do this?
Short description
To install a GUI on your EC2 Linux instance, do the following:
- Install the MATE desktop environment. MATE is a lightweight GUI based on GNOME 2 available as an extra for Amazon Linux 2. The Amazon Linux 2 offering of Amazon WorkSpaces uses MATE. For more information about MATE, see the MATE desktop environment website.
- Install a virtual network computing (VNC) service, such as TigerVNC. For more information about TigerVNC, see the tigervnc.org website.
- Connect to the GUI using the VNC.
- (Optional) Install a web browser, such as Firefox or Chromium. For more information on Firefox, see the mozilla.org website. For more information on Chromium, see the chromium.org website.
Note: These instructions apply only to Amazon Linux 2. To confirm the version that you’re running, run the following command:
For instructions on accessing an EC2 macOS instance using a GUI, see How can I access my Amazon EC2 Mac instance through a GUI?
Resolution
Before you begin
The instance must be in a public subnet and accessible through a public IP address or an Elastic IP address. Or, you can establish a connection using AWS VPN or AWS Direct Connect that allows you to access your instance through a private IP. These instructions don’t apply to environments using a bastion host. For security reasons, traffic to the VNC server is tunneled using SSH. It’s a best practice to avoid opening VNC ports in your security groups.
2. Update your instance by running sudo yum update, and then reboot the instance. Failure to update and reboot can lead to unpredictable results when following the steps below.
Install the MATE desktop environment
1. Install MATE packages.
2. Define MATE as your default desktop.
To define MATE for all users:
To define MATE for the current user only (ec2-user):
Install TigerVNC
1. Install TigerVNC packages:
2. Configure a VNC-specific password containing 6 to 8 characters for this user. When asked if you want to enter a view-only password, press «n».
3. Start the VNC Server on display number 1.
Enter the following command to start the VNC Server only once:
Note: Entering this command prevents the service from coming up after a reboot.
Enter the following commands to always start the VNC Server at boot time:
Create a new systemd unit.
Use the sed command to replace all occurrences of USER in the new unit with ec2-user.
Reload the systemd manager configuration.
Enable the service.
Start the service.
Connect to the GUI using the VNC
1. Install the TigerVNC software on your local computer, if it’s not already installed. TigerVNC is available for Linux, Windows, and macOS. See the TigerVNC website to access the download.
2. 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:
Use the -L parameter to enable port forwarding. Replace PEM_FILE with the path for your private key. Replace INSTANCE_IP with your instance’s public or private IP, as appropriate.
Open the connection.
3. Open the VNC Client on your local computer. When asked for the VNC server hostname, enter localhost:1 and then connect to it.
4. 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. Although VNC data is unencrypted by default, you’re accessing the VNC server using an encrypted SSH tunnel.
Your MATE desktop environment appears.
(Optional) Install a web browser
AWS currently doesn’t provide web browsers such as Mozilla Firefox or Google Chromium in Amazon Linux 2 repositories. To install one of these browsers, follow the steps below.
Note: AWS doesn’t provide support for software installed from third-party sources.
To install Chromium (open-source version of Google Chrome), do the following:
1. Enable the EPEL repository. See the EPEL documentation on the Fedoraproject.org website for more information.
2. Install Chromium packages.
Chromium installs on MATE under Applications, Internet, Chromium Web Browser.
To install Mozilla Firefox (current user only), do the following:
1. Download the latest Firefox version for Linux 64-bit to your local computer. See the mozilla.org website to access the download.
3. Extract the file contents. The command below indicates that the file is in the ec2-user’s home directory. Change the path and the Firefox version as needed.
4. Using vim or your favorite editor, create a desktop icon. Create the file
/Desktop/Firefox.desktop with the contents as shown in the following example.
5. Use the icon you created in step 4 on your desktop to launch Firefox.
Did this article help?
Do you need billing or technical support?
Источник
Connect to your Linux instance using SSH
After you launch your instance, you can connect to it and use it the way that you’d use a computer sitting in front of you.
The following instructions explain how to connect to your instance using an SSH client. If you receive an error while attempting to connect to your instance, see Troubleshoot connecting to your instance. For more connection options, see Connect to your Linux instance.
Prerequisites
Before you connect to your Linux instance, complete the following prerequisites.
After you launch an instance, it can take a few minutes for the instance to be ready so that you can connect to it. Check that your instance has passed its status checks. You can view this information in the Status check column on the Instances page.
Get the public DNS name and user name to connect to your instance
To find the public DNS name or IP address of your instance and the user name that you should use to connect to your instance, see Prerequisites for connecting to your instance.
Locate the private key and set the permissions
To locate the private key that is required to connect to your instance, and to set the key permissions, see Locate the private key and set the permissions.
Install an SSH client on your local computer as needed
Your local computer might have an SSH client installed by default. You can verify this by typing ssh at the command line. If your computer doesn’t recognize the command, you can install an SSH client.
Recent versions of Windows Server 2019 and Windows 10 — OpenSSH is included as an installable component. For more information, see OpenSSH in Windows .
Earlier versions of Windows — Download and install OpenSSH. For more information, see Win32-OpenSSH .
Linux and macOS X — Download and install OpenSSH. For more information, see https://www.openssh.com .
Connect to your Linux instance using an SSH client
Use the following procedure to connect to your Linux instance using an SSH client. If you receive an error while attempting to connect to your instance, see Troubleshoot connecting to your instance.
To connect to your instance using SSH
In a terminal window, use the ssh command to connect to the instance. You specify the path and file name of the private key ( .pem ), the user name for your instance, and the public DNS name or IPv6 address for your instance. For more information about how to find the private key, the user name for your instance, and the DNS name or IPv6 address for an instance, see Locate the private key and set the permissions and Get information about your instance. To connect to your instance, use one of the following commands.
(Public DNS) To connect using your instance’s public DNS name, enter the following command.
(IPv6) Alternatively, if your instance has an IPv6 address, to connect using your instance’s IPv6 address, enter the following command.
You see a response like the following:
(Optional) Verify that the fingerprint in the security alert matches the fingerprint that you previously obtained in (Optional) Get the instance fingerprint. If these fingerprints don’t match, someone might be attempting a «man-in-the-middle» attack. If they match, continue to the next step.
You see a response like the following:
Transfer files to Linux instances using an SCP client
One way to transfer files between your local computer and a Linux instance is to use the secure copy protocol (SCP). This section describes how to transfer files with SCP. The procedure is similar to the procedure for connecting to an instance with SSH.
Verify the general prerequisites for transferring files to your instance.
The general prerequisites for transferring files to an instance are the same as the general prerequisites for connecting to an instance. For more information, see General prerequisites for connecting to your instance.
Install an SCP client
Most Linux, Unix, and Apple computers include an SCP client by default. If yours doesn’t, the OpenSSH project provides a free implementation of the full suite of SSH tools, including an SCP client. For more information, see https://www.openssh.com .
The following procedure steps you through using SCP to transfer a file using the instance’s public DNS name, or the IPv6 address if your instance has one.
To use SCP to transfer files between your computer and your instance
Determine the location of the source file on your computer and the destination path on the instance. In the following examples, the name of the private key file is my-key-pair.pem , the file to transfer is my-file.txt , the user name for the instance is ec2-user, the public DNS name of the instance is my-instance-public-dns-name , and the IPv6 address of the instance is my-instance-IPv6-address .
(Public DNS) To transfer a file to the destination on the instance, enter the following command from your computer.
(IPv6) To transfer a file to the destination on the instance if the instance has an IPv6 address, enter the following command from your computer. The IPv6 address must be enclosed in square brackets ( [ ] ), which must be escaped ( \ ).
If you haven’t already connected to the instance using SSH, you see a response like the following:
(Optional) You can optionally verify that the fingerprint in the security alert matches the instance fingerprint. For more information, see (Optional) Get the instance fingerprint.
If the transfer is successful, the response is similar to the following:
To transfer a file in the other direction (from your Amazon EC2 instance to your computer), reverse the order of the host parameters. For example, you can transfer my-file.txt from your EC2 instance to the a destination on your local computer as my-file2.txt , as shown in the following examples.
(Public DNS) To transfer a file to a destination on your computer, enter the following command from your computer.
(IPv6) To transfer a file to a destination on your computer if the instance has an IPv6 address, enter the following command from your computer. The IPv6 address must be enclosed in square brackets ( [ ] ), which must be escaped ( \ ).
Troubleshoot
If you receive an error while attempting to connect to your instance, see Troubleshoot connecting to your instance.
Источник
Tutorial: Get started with Amazon EC2 Linux instances
Use this tutorial to get started with Amazon Elastic Compute Cloud (Amazon EC2). You’ll learn how to launch, connect to, and use a Linux instance. An instance is a virtual server in the AWS Cloud. With Amazon EC2, you can set up and configure the operating system and applications that run on your instance.
Contents
If you’d prefer to launch a Windows instance, see this tutorial in the Amazon EC2 User Guide for Windows Instances: Get started with Amazon EC2 Windows instances.
If you’d prefer to use the command line, see this tutorial in the AWS Command Line Interface User Guide: Using Amazon EC2 through the AWS CLI.
Overview
The instance is an Amazon EBS-backed instance (meaning that the root volume is an EBS volume). You can either specify the Availability Zone in which your instance runs, or let Amazon EC2 select an Availability Zone for you. When you launch your instance, you secure it by specifying a key pair and security group. When you connect to your instance, you must specify the private key of the key pair that you specified when launching your instance.
Prerequisites
Before you begin, be sure that you’ve completed the steps in Set up to use Amazon EC2.
Step 1: Launch an instance
You can launch a Linux instance using the AWS Management Console as described in the following procedure. This tutorial is intended to help you launch your first instance quickly, so it doesn’t cover all possible options. For more information about the advanced options, see Launch an instance using the Launch Instance Wizard. For information about other ways to launch your instance, see Launch your instance.
To launch an instance
From the console dashboard, choose Launch Instance.
The Choose an Amazon Machine Image (AMI) page displays a list of basic configurations, called Amazon Machine Images (AMIs), that serve as templates for your instance. Select an HVM version of Amazon Linux 2. Notice that these AMIs are marked «Free tier eligible.»
On the Choose an Instance Type page, you can select the hardware configuration of your instance. Select the t2.micro instance type, which is selected by default. The t2.micro instance type is eligible for the free tier. In Regions where t2.micro is unavailable, you can use a t3.micro instance under the free tier. For more information, see AWS Free Tier .
On the Choose an Instance Type page, choose Review and Launch to let the wizard complete the other configuration settings for you.
On the Review Instance Launch page, under Security Groups, you’ll see that the wizard created and selected a security group for you. You can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:
Choose Edit security groups.
On the Configure Security Group page, ensure that Select an existing security group is selected.
Select your security group from the list of existing security groups, and then choose Review and Launch.
On the Review Instance Launch page, choose Launch.
When prompted for a key pair, select Choose an existing key pair, then select the key pair that you created when getting set up.
Don’t select Proceed without a key pair. If you launch your instance without a key pair, then you can’t connect to it.
When you are ready, select the acknowledgement check box, and then choose Launch Instances.
A confirmation page lets you know that your instance is launching. Choose View Instances to close the confirmation page and return to the console.
On the Instances screen, you can view the status of the launch. It takes a short time for an instance to launch. When you launch an instance, its initial state is pending . After the instance starts, its state changes to running and it receives a public DNS name. (If the Public IPv4 DNS column is hidden, choose the settings icon ( ) in the top-right corner, toggle on Public IPv4 DNS, and choose Confirm.
It can take a few minutes for the instance to be ready so that you can connect to it. Check that your instance has passed its status checks; you can view this information in the Status check column.
Step 2: Connect to your instance
There are several ways to connect to your Linux instance. For more information, see Connect to your Linux instance.
You can’t connect to your instance unless you launched it with a key pair for which you have the .pem file and you launched it with a security group that allows SSH access from your computer. If you can’t connect to your instance, see Troubleshoot connecting to your instance for assistance.
Step 3: Clean up your instance
After you’ve finished with the instance that you created for this tutorial, you should clean up by terminating the instance. If you want to do more with this instance before you clean up, see Next steps.
Terminating an instance effectively deletes it; you can’t reconnect to an instance after you’ve terminated it.
To terminate your instance
In the navigation pane, choose Instances. In the list of instances, select the instance.
Choose Instance state, Terminate instance.
Choose Terminate when prompted for confirmation.
Amazon EC2 shuts down and terminates your instance. After your instance is terminated, it remains visible on the console for a short while, and then the entry is automatically deleted. You cannot remove the terminated instance from the console display yourself.
Next steps
After you start your instance, you might want to try some of the following exercises:
Learn how to remotely manage your EC2 instance using Run Command. For more information, see AWS Systems Manager Run Command in the AWS Systems Manager User Guide.
Configure a CloudWatch alarm to notify you if your usage exceeds the Free Tier. For more information, see Tracking your AWS Free Tier usage in the AWS Billing and Cost Management User Guide.
Install the LAMP stack. For more information, see Tutorial: Install a LAMP web server on Amazon Linux 2.
Источник