How to Create a Linux Server in the Cloud Using AWS EC2

Hosting web servers on the Internet can be very challenging for a beginner without proper guidance. Cloud service providers have provided numerous ways to easily spin up servers of any type in the cloud.


AWS is one of the largest and most reliable cloud-based server deployment options. How to get your Linux-based server up and running in the cloud with AWS EC2.


What is Amazon EC2?

Amazon Elastic Cloud Compute (EC2) is one of Amazon’s most popular web services. With EC2 you can create virtual machines in the cloud with different operating systems and adaptable computing capacity. This is very useful for starting secure web servers and making them available on the internet.

How to create a Linux EC2 instance

The AWS web console provides an easy-to-navigate interface that you can use to launch an instance without using scripts or code. Here is a step-by-step guide to launching a Linux-based EC2 instance on AWS. You will also learn how to connect securely using the console.

Sign in to your existing AWS account or go to portal.aws.amazon.com to sign up for a new one. Then search and navigate to EC2 Dashboard.

Find them start instances button in the top right corner of the screen and click it to launch the EC2 Startup Wizard.

The first required step is to enter a name for your instance. Next, choose the operating system image and version (Amazon Machine Image AMI) of the Linux distribution that you want to use. You are free to explore other recommended Linux server operating systems other than Ubuntu.

Choose an instance type

The different EC2 instance types consist of different combinations of CPU, memory, storage, and network performance. Depending on your needs, you can choose from up to 10 different instance types. For demonstration let’s go with the default (t2.micro) instance type.

AWS has an article on choosing the right instance type for your EC2 virtual machine that you can use as a reference.

Choose a key pair

In most cases, at least for development and debugging purposes, you may need to access your instance via SSH, and to do that securely you need a key pair. This is an optional configuration, but since you may later connect to your instance via SSH, you’ll need to add a key pair.

You can either use an existing key pair or create a new one. To create a new one, click Create a new key pairand you will see the popup screen below.

Give your key pair a name and choose an encryption type (RSA is the most popular and recommended option as it is supported on multiple platforms). You also need to choose a file format (PEM or PPK) for the private keys that will be downloaded to your local computer, depending on the SSH client you use.

That network settings for your EC2 instance are next. By default, you need to create a new security group to define firewall rules to restrict access only to specific ports on your instance.

It is recommended to limit the SSH connection to your IP address only to reduce the chances of your server being hacked. You should also allow HTTP traffic if you created the instance as a web server.

You can always go back to edit your security group rules to add or remove inbound and outbound rules. For example, add inbound rules for HTTPS traffic when setting up an SSL certificate for secure HTTP connections.

storage settings

By default, EC2 allocates storage based on the selected instance type. However, you have the option of adding an Amazon Elastic Block Storage volume (which acts like an external storage disk) to your instance.

This isn’t mandatory, but if you want a virtual disk that you can use in multiple instances or move around easily, it’s worth considering. You can now review your instance configuration to make sure everything is set up correctly, and then click Start instance button to create your Linux virtual machine.

You will be taken to a screen where you have the View Instances Button. Click on it to view your newly launched instance.

How to connect to a Linux EC2 instance

Now that the virtual machine is up and running, you can set up a web server in it. It could be an Apache server, Node.js server or whatever server you want to use. There are up to four different ways to connect to an EC2 instance, namely:

  • Connect EC2 instance
  • session manager
  • SSH client
  • EC2 Serial Console

The most common connection methods are Connect EC2 instance and SSH client. EC2 Instance Connection is the fastest and easiest way to connect to your EC2 instance and perform the operations you want on it.

To connect to your Linux instance using EC2 instance connection, select it on the dashboard and click Connect.

Choose Connect EC2 instance tab and click on the Connect Button. This would automatically open a screen that looks like a command line interface.

This confirms a successful login to your Linux machine, and you can now begin setting it up for your web server needs. For example, to create a simple Apache web server, run the following commands:

sudo apt-get update -y
sudo apt-get install apache2 -y
sudo systemctl start apache2.service

To check if everything went well and the Apache server is up and running, check the status with sudo systemctl status apache2.service. If everything is ok, you should have an output similar to the following:

Finally, you can test the server by running the Public IPv4 DNS from the Instance Properties tab and paste it into your browser. You should see the Apache demo page.

Congratulations on successfully setting up your Linux server on the AWS cloud. You can now build your applications with it and deploy them to production.

Deploying applications in the cloud with AWS

Now you can easily set up a Linux web server in the cloud with Amazon EC2. While Ubuntu is the most common operating system for Linux servers, the process of creating an EC2 instance is the same for any other Linux distribution.

You can also set up different types of web servers like Node.js, Git, Golang or a Docker container. All you have to do is connect to your instance and follow the steps to set up your preferred application server.

Leave a Reply

Your email address will not be published. Required fields are marked *