EC2 Ubuntu
EC2 Ubuntu
Ubuntu 18.04
Prerequisites:
AWS Account with IAM user
Create KeyPair
Steps:
Launch Instance
Pick Ubuntu
Scroll down to attach the key pair. We will use the key pair to ssh
into our Ubuntu server.
Create instance
Once you see “running” under instance state, you can move to
the next step
Implementation:
The steps taken to complete this tutorial are being stated below:
Step 1: Go to portal.aws.amazon.com to create a new AWS
account. Provide email address and password. Click Continue.
Step 2: Provide other details like Name, Phone Number, etc., and
click Continue when done.
Step 3: Provide billing information and click ‘Verify and
Continue’.
Step 4: Confirm your identity and click ‘Send SMS’. Confirm the
OTP.
Step 5: Select a plan. Here, we choose ‘Basic support – Free’ and
click on ‘Complete sign up’.
Step 10: On the left pane, click on Instances under the Instances
section. Click ‘Launch instances’.
Step 11: Now, we choose an Amazon Machine Image (AMI).
Search for ‘ubuntu server 18.04 LTS’ and click Select.
Step 14: Set the size as 8 GiB and click ‘Next: Add Tags’.
Step 15: Click ‘Next: Configure Security Group’.
Step 16: Choose ‘Create a new security group’ and add SSH,
HTTP, and HTTPS Types. Click ‘Review and Launch’ when done.
Step 17: Click Launch.
Step 18: Select ‘Create a new key pair’ and enter any key pair
name in the given field. Leave the ‘Key pair type’ as RSA. Click
‘Download Key Pair’ to download the .pem file. Store it in a secure
location as it will be used later. Click ‘Launch Instances’.
Step 19: Click ‘View Instances’.
Step 20: We can now see our instance named ‘inst1’ running.
Step 21: Go to putty.org to download PuTTY. Click on ‘here’.
Step 22: Under MSI (‘Windows Installer’) click the first link (next
to 64-bit x86) to download PuTTY.
Step 23: Go to puttygen.com to download PuTTYgen. Click on
‘PuTTY Installation Download page’.
Step 26: Specify the install location for PuTTY. Click Next.
Step 27: Click Install.
Step 34: Open PuTTY and enter the public IP of the instance in
Host Name filed and keep Port as 22.
Step 35: Select Auth under SSH and click on Browse.
Step 36: Select the .ppk file (ubuntuppk.ppk) and click Open.
Step 42: Verify that Apache is running using the command ‘sudo
systemctl status apache2’.
Step 43: Copy the public IP of the EC2 instance and paste it on a
browser of the host OS.
Step 46: This is the default code. We need to replace this code
with our own code for the sample webpage.
Step 47: The default code is replaced with our own code in
index.html. Save and exit the editor.
Step 48: We can verify that we are able to access the hosted
webpage using ‘curl’ inside the instance.
Step 49: The hosted web page can also be accessed from the
host OS as shown.
Step 50: The hosted web page can also be accessed by another
system (a smartphone – iOS 14.7.1) as shown.
How to convert a PEM file to PPK format
.pem (Privacy-Enhanced Mail) and . ppk (PuTTY Private Key)
When you create an Amazon EC2 instance, AWS generates the access
keys in a Privacy Enhanced Mail (PEM) format.
For those who want to PuTTY to their EC2 instance, there’s a complication:
PuTTY does not natively support the PEM file format. You must convert the
PEM to a PPK file in order to PuTTY into the instance.
PEM to PPK conversion steps
Here are the steps to quickly convert a PEM to a PPK file with PuTTYGen:
5. Click Save Private Key and PuTTYGen will convert the PEM to a PPK file
Step 3 often causes problems, because the file selector is set to PPK so the PEM
will not be visible even if you select the correct folder. Just change the filetype to
*.* and every filetype will be visible.
Upon import, PuTTYgen explains how to convert an SSH PEM to a PPK format for use with PuTTY.
Connect to EC2 from PuTTY
Once the PEM to PPK conversion is complete, simply register the PPK file in
PuTTY’s SSH authentication tab.
To SSH into an EC2 instance, find the SSH URL in the SSH client tab of the EC2
instances’ connection tab. Paste this in as PuTTY’s hostname and click Open.
Once the connection is made, you can issue commands and configure your EC2
instance at will.
And that’s how easy it is to convert a PEM file to PPK format and PuTTY into
remote servers such as Amazon EC2 instances.
Table of Contents
Steps to Install Apache 2 on AWS EC2 Instance Ubuntu 20.04
Step 1: Launch an EC2 Instance(Ubuntu 20.04)
Step 2: Connect to your EC2 instance
o To SSH from browser using Instance connect, follow below steps.
Step 3: Install Apache Web Server
o Explanation of commands
o Update latest package available on the system
o Install Apache Web Server
o Verify Apache Installation
o Check Apache Server Status
Step 4: Change Security Group of instance to allow port 80 and 443
Step 5: Verify the Installation by Accessing the Server
Step 6: Customize the web page
Step 7: View the customized web page
o Other important commands:
Important Note: Please note that, above tutorial uses Linux 2 AMI.
However, to create Ubuntu instance you need to
select Ubuntu while choosing AMI for your instance. Rest of the
process for creating instance remains same.
While you are in Choose AMI screen, search for ubuntu keyword
and select ubuntu server 20.04(free tier eligible) as shown below.
Here is how it looks while choosing AMI.
Step 2: Connect to your EC2 instance
Once your instance is up and running, you need to connect to your
instance. I will be using EC2 instance connect feature for this. It
allows you to SSH into instance from browser itself.
Lazy me 😛
2. Once, you click Connect, you will see a screen with default
username for ubuntu instance
Verify that ubuntu is showing in username field and click Connect.
A new browser window will open and you will be connected into
your instance like below.
Amazing !!!
Now, you are ready to run commands on your EC2 instance. Let’s
move to the installation part in next step.
apache2 -version
Explanation of commands
Update latest package available on the
system
It’s a best practice to update all the packages to latest before
installing anything new.
apache2 -version
Why?
Specify rules for HTTP and HTTPS Web traffic from anywhere like
above.
Therefore, our instance allows web traffic now, it’s time to grab the
public IP or public dns of the instance.
Click on open address and you should be able to see the default
page like below.
Step 6: Customize the web page
We have seen the default apache page served by apache. Lets
modify that.
But using ‘>’ creates a problem and the the above command ends
up running as ubuntu instead of root resulting in permission denied
like below.
Let’s switch our user to root here by using sudo su. As you can see
in below screenshot, after using this command, root becomes the
current user.
After switching the user try that command again but this time
without sudo as we already are running it as sudo