DEV Community

Cover image for Creating an Amazon EC2 instance with remote root user access and configuring an usage alerting
Rodrigo Kamada for AWS Community Builders

Posted on • Edited on

Creating an Amazon EC2 instance with remote root user access and configuring an usage alerting

Introduction

In this article, an Amazon EC2 (Elastic Compute Cloud) instance will be created using the Amazon Linux 2023 AMI operating system image, the root user will be configured to access the remote virtual server via SSH, and a free tier usage alert will be configured.

Prerequisites

Before you start, you need to install and configure the tools below to access the remote server.

  • AWS Account: Amazon Web Services is a cloud computing services platform and it will be used to create the Amazon EC2 instance.
  • SSH Client: Secure Shell is a protocol for sending commands securely to a remote server and it will be used to access the virtual server.
  • Terminal: Terminal is the visual interface where the user types commands and views results by interacting with the operating system programs.

Getting started

Create the instance on Amazon EC2

Amazon EC2 (Elastic Compute Cloud) is a scalable cloud infrastructure service that allows you run virtual servers, select multiple operating systems and processors options, configure network security and manage storage and memory. You can add or reduce resource capacity according to your business needs.

1. Let's access the AWS account. Access the site https://aws.amazon.com/ec2/ and click on the button Sign In to the Console.

Amazon EC2 - Home page

2. Now we will click on the button Sign in using root user email.

Amazon EC2 - IAM user sign in

3. Next, we will click on the option Root user, fill in the field Email address and click on the button Next.

Amazon EC2 - Sign in

4. Then, we will fill in the field Password and click on the button Sign in.

Amazon EC2 - Root user sign in

5. After sign in, we will type ec2 in the search field and click on the option EC2.

Amazon EC2 - Search EC2

6. Now we will click on the link Instances (running).

Amazon EC2 - Dashboard

7. Next, we will click on the button Launch instances.

Amazon EC2 - Instances

8. Then, we will fill in the field Name, select the option Amazon Linux 2023 AMI in the field Amazon Machine Image (AMI), select the option Proceed without a key pair (Not recommended) in the field Key pair name - required and click on the button Launch instance.

Amazon EC2 - Launch an instance

9. Ready! The Amazon EC2 instance was created with the Amazon Linux 2023 AMI operating system.

Amazon EC2 - Instance initiated

Create the root user access

1. Let's create access for the root user. We will click on the menu Instances.

Amazon EC2 - Instance created

2. Now we will click on the link of the instance created.

Amazon EC2 - Instances created

3. Next, we will click on the tab Connect.

Amazon EC2 - Instance summary

4. Then, we will click on the button EC2 Instance Connect.

Amazon EC2 - Connect to instance

5. After access the tab EC2 Instance Connect, we will click on the button Connect.

Amazon EC2 - EC2 Instance Connect

6. Now we will type the command sudo -i to log in with the user root.

Amazon EC2 - Log in with the root user

7. Next, we will type the command passwd to configure the root user password.

Amazon EC2 - Configure the root user password

8. Then, we will add the remote access settings for the root user in the file /etc/ssh/sshd_config.

PermitRootLogin yes
PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode

9. After add the remote access settings for the root user, we will type the command systemctl restart sshd to restart the SSH service.

Amazon EC2 - Restart the SSH service

10. Now we will test the remote access with the root user. We will go to the page that contains the instance informations and click on the icon to copy the public IP address.

Amazon EC2 - Copy the public IP address

11. Next, we will type the command ssh root@3.80.139.206 using public IP address to access the remote virtual server.

ssh root@3.80.139.206
The authenticity of host '3.80.139.206 (3.80.139.206)' can't be established.
ED25519 key fingerprint is SHA256:iQxE9Tn+UVDJGCQPe0ImkZ4W+/akI3VEiyHaHipPUXU.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:46: ec2-3-80-139-206.compute-1.amazonaws.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '3.80.139.206' (ED25519) to the list of known hosts.
root@3.80.139.206's password: 

A newer release of "Amazon Linux" is available.
  Version 2023.6.20250123:
Run "/usr/bin/dnf check-release-update" for full release and version update info
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
Last failed login: Sat Jan 25 14:30:25 UTC 2025 from 187.180.189.101 on ssh:notty
There were 82 failed login attempts since the last successful login.
Enter fullscreen mode Exit fullscreen mode

12. Ready! The remote access to the root user was created and tested.

Create the root user access

The free tier usage alert helps you monitor your AWS service usage and cost by sending you email notifications when you exceed 100% of your free tier limit.

1. Let's create the free tier usage alert. We will click on the user menu and click on the menu Billing and Cost Management.

Amazon EC2 - Menu Billing and Cost Management

2. Now we will click on the menu Billing Preferences.

Amazon EC2 - Home Billing and Cost Management

3. Next, we will click on the button Edit.

Amazon EC2 - Billing preferences

4. Then, we will click on the option Receive AWS Free Tier alerts, fill in the field Email address to receive Free Tier usage alerts - optional and click on the button Update.

Amazon EC2 - Edit the billing preferences

5. Ready! The free tier usage alert was created.

Amazon EC2 - Alert created

Conclusion

Summarizing what was covered in this article:

  • We created an Amazon EC2 instance using the Amazon Linux 2023 AMI operating system image.
  • We created the root user access to access the remote virtual server.
  • We created the free tier usage alert to monitor the usage and cost of AWS services.

You can use this article to create a virtual server, install and run a database or an HTTP server or an application in a certain programming language.

Thank you for reading and I hope you enjoyed the article!

This tutorial was posted on my blog in portuguese.

To stay updated whenever I post new articles, follow me on Twitter and LinkedIn.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Create a simple OTP system with AWS Serverless cover image

Create a simple OTP system with AWS Serverless

Implement a One Time Password (OTP) system with AWS Serverless services including Lambda, API Gateway, DynamoDB, Simple Email Service (SES), and Amplify Web Hosting using VueJS for the frontend.

Read full post

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay