Creating and Managing EC2 Instances on AWS: A Comprehensive Guide

Dr. Ernesto Lee
4 min readSep 23, 2023

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It enables users to run virtual servers, known as instances, allowing for scalable deployment of applications.

In this article, we will walk you through creating a Linux instance and connecting to it using PuTTY. We will then proceed to create an instance with a UI (User Interface) and connect to it from a browser. Lastly, we will guide you on how to delete these resources.

Creating a Linux EC2 Instance

Step 1: Launching an Instance

  1. Sign in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. Click Launch Instance.
  4. In the “Choose an Amazon Machine Image (AMI)” step, select a Linux AMI, like Amazon Linux 2 AMI.
  5. Choose an instance type. For this tutorial, we’ll use the t2.micro instance type, which is eligible for the free tier.
  6. Configure instance details as per your needs and proceed to the “Add Storage” step.
  7. Add necessary storage and proceed to the “Configure Security Group” step.
  8. Create a new security group with necessary rules. For SSH, open port 22.

Step 2: Accessing the Instance using PuTTY

  1. Once your instance is running, select it in the EC2 Dashboard and note the Public IP.
  2. Convert your PEM file to PPK using PuTTYgen.
  3. Open PuTTY, input the public IP in the “Host Name” field, and load the PPK file under SSH > Auth.
  4. Click “Open” and accept the security alert to connect to your instance.

Creating an EC2 Instance with a UI

Step 1: Launching an Instance with a UI

  1. Follow the same steps as before but choose an AMI with a desktop environment, like Ubuntu Server with GUI.
  2. In the “Configure Security Group” step, add a rule to allow TCP traffic on port 80 and 443 for HTTP/HTTPS access.

Step 2: Accessing the Instance using a Browser

  1. After the instance is running, install a web-based desktop access software like xrdp.
  2. Access the desktop environment using a web browser by navigating to the public IP of the instance.

Deleting EC2 Instances and Resources

Step 1: Terminating Instances

  1. Navigate to the EC2 Dashboard.
  2. Select the instance you want to terminate.
  3. Choose Actions > Instance State > Terminate Instance.
  4. Confirm the termination.

Step 2: Deleting Security Groups

  1. In the EC2 Dashboard, go to Security Groups under Network & Security.
  2. Select the security group you want to delete.
  3. Click Actions > Delete security group.

Step 3: Releasing Elastic IPs

  1. In the EC2 Dashboard, go to Elastic IPs under Network & Security.
  2. Select the Elastic IP you want to release.
  3. Choose Actions > Release addresses.

Conclusion

Amazon EC2 allows users to deploy scalable applications using virtual servers in the cloud. This article provided step-by-step instructions on creating and connecting to Linux instances with and without a UI, using PuTTY and a web browser respectively. Don’t forget to delete any unused resources to avoid unnecessary charges!

Note:

  • Ensure that all your data is backed up before terminating instances as the data on the instance will be lost.
  • The steps provided are for educational purposes, and it’s crucial to configure security settings appropriately in a production environment.

References:

  1. Amazon EC2 Documentation
  2. PuTTY Documentation
  3. xrdp Documentation

Yes, you can log in to a Linux instance with a username and password, although by default, Amazon EC2 instances are accessed using key pairs and not passwords. However, you can enable password authentication by modifying the SSHD configuration file on your instance.

Step-by-Step Guide to Enable Password Authentication

  1. Connect to your EC2 instance using a key pair, as you normally would. For Amazon Linux, the default user is ec2-user.
  2. Open the SSHD Config file in a text editor (e.g. vi, nano). Run the command:
sudo nano /etc/ssh/sshd_config
  1. Modify the SSHD Config File:
  • Find the line that says PasswordAuthentication no.
  • Change it to PasswordAuthentication yes.
  1. Save the changes and exit the text editor.
  2. Restart the SSHD Service to apply the changes. Run the command:
sudo service sshd restart

Set a Password for the User:

  • You will need to set a password for the user you want to log in with. If you are using the ec2-user, run:
  • Follow the prompts to enter and confirm the new password.

Logging in with a Username and Password

Once you have enabled password authentication and set a password for the user, you can log in with the username and password using an SSH client like PuTTY.

  1. Open PuTTY.
  2. Enter your EC2 instance’s public IP in the “Host Name” field.
  3. Under Connection type, select SSH.
  4. Click “Open”.
  5. When prompted, enter the username (e.g., ec2-user).
  6. When prompted for the password, enter the password you have set up.

Security Consideration

Using passwords can expose your instance to brute force attacks, and it is generally considered less secure than using key pairs. If you decide to use password authentication, it is highly recommended to use strong, unique passwords and consider additional security measures such as setting up a firewall, using fail2ban, or configuring a VPN.

Important Note:

Always ensure you have another way to access your instance before changing the SSH configuration, such as having another user with SSH key access or having AWS Systems Manager Session Manager enabled, to avoid being locked out of your instance.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

What are your thoughts?