Published in



Creating a Linux instance in AWS

Start to leverage the power of cloud computing in minutes for free with AWS

If you’re involved in the tech industry, you're likely to come across Linux, and will probably need to use it at some point. Get started now by following this simple guide to launching a Linux instance in the cloud.

From hosting web apps, databases, application testing or integration builds, cloud computing can provide an incredibly cost-effective way to achieve your goals.

Linux has a wild amount of variations known as “distros”. Red Hat (RHEL) SUSE and CentOS are common RPM-based distros and Ubuntu is probably one of the most common Debian based distros. There are a lot of core similarities between distros. When starting out you may struggle to see many but they are there, and it pays to do some research into what will work best for you.

This guide will explain:

  • creating a budget to prevent any unwanted spending
  • set up an EC2 Linux instance including storage and security
  • connecting to the new instance via SSH

AWS offers a wide variety of machine images (AMIs) which you can select to launch your instance from. In this example, I’ll use Ubuntu 20.04, but really you can use any Linux AMI you want.

To start with you need to create an AWS account, this is quick and easy. Once created you’ll arrive at the AWS console where you are presented with a world of services now available. It’s worth checking the free tier page at this point to know what you’ll get for free in your first year, and what you’ll get charged for.


A good safety net when starting out to prevent you from accidentally running up a bill with AWS is to set a budget. To quickly set one up, type billing in the search bar at the top of the page to find the billing service. From there click budgets.

Click create a budget, and select a cost budget for the first step. Next, give it a name, set the period to monthly and keep it as a recurring budget. Below, leave it as a fixed budget and set an amount. I would recommend setting the first budget at $0.01 so that you are warned the second you incur a charge. You can then go on to set some more budgets at $0.10 and maybe $1 if your feeling like splashing some cash. Ignore everything else, and go to the next step.

Set your threshold based on actual cost, and the threshold to 100%. Add your email address so you can be notified, confirm and create the budget. You’ll receive emails as soon as a budget is exceeded.

Creating an Instance

From the services search bar at the top navigate to EC2. This stands for Elastic Compute Cloud. The elastic part essentially means that the computing service is scalable and can be easily expanded to meet computing needs.

The EC2 console will provide you with an almost overwhelming amount of features and services covering storage computing and security. We will focus on launching an instance, which will involve a small amount of interaction with the security and storage features but the launch wizard makes this all quite easy to deal with.

Look for the orange “Launch instance” drop-down button, and select “Launch Instance”. Here you will be presented with a list of AMIs. Look for ones that have “free tier eligible” under the instance logo. Select the Linux instance you want to use.

Next, the instance type allows you to choose the computing power of your instance. You can achieve a surprising amount with the free tiers “t2.micro” instance. With that selected, click “Next: Configure Instance”.

All of the defaults on the Configure Instance step should be fine, but it’s worth reading through them to understand what you can control. An important setting is the “IAM Role”. A specified role enables your instance to interact with other services. AWS follows a common security concept of least privilege, which means your instance can’t interact with anything unless specifically given permission to.

Another interesting field here is “User Data” at the very bottom. This can be a script the instance will run on launch. Handy if you are frequently launching instances, and require them to have the same setup, such as installing packages or running services.

Next, add storage. It’s key to note here that when an instance is destroyed, all the data stored on it is gone too. Elastic Block Storage (EBS) allows you to have persistent data, that you can move between instances. Each block can only be attached to one instance at a time. If you are wanting to understand how to manage storage in Linux, such as using partitions and logical volumes, add a few blocks here to give you something to play with on launch.

Next, add tags. This can be useful for identifying resources. Having a good tagging strategy is valuable as your cloud infrastructure starts to grow, and can help manage usage costs too.

Next, configure security groups. Think of a security group as a list for a bouncer at an exclusive night club called Your-EC2. If you are on the list, you are allowed into the instance, every one else can go to Wetherspoons. This again is an application of the least privilege security principle. For now, we just need to allow an SSH connection from your personal computer. In the future, you may want to allow other ports to be accessible for web or database traffic.

To set this up, the defaults should get you going, with type SSH, protocol TCP and port 22. You need to set the source to your IP. Fortunately, this is easy. Click the drop-down in the source column, select “My IP”. Then give this rule a description.

Review and Launch! Double-check all of your settings and click Launch. You are presented with a pop-up to select a key pair. A key pair enables secure communication between the holder of the key and the instance. Select “Create a new key pair” from the first drop down, and give it a name. Key’s are relative to the region you are launching in and only accessible in that region.

With the key downloaded, you can launch the instance.

Back in your EC2 console, you can select instances from the resources section or nav bar on the left. You should see a table with your new instance, and the state will quickly change to running. Once running you can connect to it. Copy the public IP of the instance and open up your terminal.

You may need to change the permission on the file to be read-only by the file owner, which can be done with the command chmod 400 your-key.pem.

In your terminal, you can run the following command to connect to your instance:

ssh -i AWS-KEY.pem ubuntu@

That command breakdown into these parts:

ssh -i <yourkey> <username>@<public-ip>

Replace AWS-KEY.pem with your key file. Remember that you either need to be in the folder where you saved your key or provide the absolute path to the location of the key. For example /Users/Me/Downloads/aws-key.pem.

If you used an Ubuntu AMI you can leave ubuntu there and just change the IP address to your instances. If you used a different AMI, you will need to change ubuntu to the username created on your instance. AWS can provide some help here. With your instance selected, click Actions in the top right, then connect. Under SSH client you will be given a walkthrough of what to do to connect.

And that’s it, your in. You now have a brand new computer to work with. Host websites, compile projects or learn the ins and outs of Linux.

To get to know the basics of Linux, read this article to learn how to navigate and manage directories and files.

If you want to dig deeper into AWS, read this article about creating infrastructure with CloudFormation.

Hopefully, this guide has got you going. Feel free to comment or ask questions!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store