Ubuntu Server Creation in AWS

Ubuntu is a Linux distribution created by Canonical. In this exercise, you will create an Ubuntu server virtual machine and connect to it.

Video Walkthrough

Use this video to follow along with the steps in this lab.

Learner Lab Login

  • Log into the AWS console through the Learner Lab course.
  • Launch the AWS Management Console to configure your AWS environment through your web browser.

Ubuntu Server Security Group

  • Click the EC2 link to open the EC2 dashboard.
  • Find the link in the left navigation that says Security Groups and open it.
  • Click Create security group.
  • Name the security group Lastname Ubuntu Server SG, replacing Lastname with your name (e.g., "Marquardson Ubuntu Server SG").
  • Change the description to Ubuntu Server SSH and ICMP.
  • Leave the VPC unchanged.
  • Under Inbound rules, click Add rule.
    • In the service, choose SSH. This will allow inbound traffic for the Secure Shell protocol. SSH uses port 22 by default.
    • In the source, choose Anywhere-IPv4. Once selected, a box showing 0.0.0.0/0 will appear. This rule allows anybody on the internet to attempt to connect to your instance and log in. Ideally, you would restrict this to only your IP address, but your IP address will change frequently. From a security standpoint, allowing connection attempts from the entire internet is not ideal, but it's a tradeoff from having to edit your security group every time you want to connect. You must have a very strong password for your login credentials, otherwise, an attacker could guess your password and log in.
  • Add another rule.
    • In the service, choose All ICMP - IPv4. This allows you to ping your virtual machine to test connectivity.
    • In the source, choose Anywhere-IPv4 again.
  • At the bottom of the page, click Create security group.
  • You should see a message saying that the security group was created successfully.

Create an Ubuntu Server EC2 Instance

  • In the EC2 service, click Instances.
    Instances Link
  • Click the Launch Instances button. This button will take you to a screen where you will configure the EC2 instance launch settings.
    Launch Instances Button

  • In the Launch an instance page, use the following settings

    • Name: Lastname Ubuntu Server (replacing Lastname with your last name, e.g., "Marquardson Ubuntu Server")
    • Application and OS Images: Ubuntu
    • Amazon Machine Image (AMI): Microsoft Ubuntu Server (Year) Base
      Ubuntu Server AMI
    • Instance Type: t2.medium (note the cost per hour)
      Instance Type
    • Key pair (login): Select the vockey key from the list.
      Key Pair Selection
    • In the Network settings, click Edit.
    • Choose the Subnet with the availability zone us-east-1e.
      Availability Zone Selection
    • Select an existing security group rather than creating a new one. Select your previously created Lastname Ubuntu Server SG security group.
    • Expand Advanced network configuration.
    • Set the Primary IP to 172.31.50.60. This will be the private IP address for the life of this EC2 instance, no matter how many times it is rebooted.
    • Underneath the networking configuration, find the Configure storage section. Set the disk to 30 GiB.
      30 Gib
    • Scroll to the bottom of the page and expand the Advanced Details section. In the IAM Profile, select LabInstanceProfile. Choosing this facilitates instance management later.
      IAM Profile Selection
    • At the bottom of the page, click Launch instance. This button starts the creation of your EC2 instance on Amazon's infrastructure.
      Launch Instance After Configuration
  • You should see a message that the instance was launched successfully.

Instance Launch Success

  • A random ID will be created for the instance. Click the ID link to view the instance status.

Connecting to the Ubuntu Server

Remote connections to Windows Server use the graphical user interface through the Remote Desktop Protocol (RDP). On Linux, the default remote connection is a command-line interface using Secure Shell (SSH).

  • The Ubuntu Server EC2 instance will appear in the list of EC2 instances. If you do not see it, click the refresh button next to the Connect button.
  • The "Status check" will show "Initializing" as the EC2 instance is being launched. It will take a few minutes for the instance to fully initialize.
    Initializing
  • Once the instance is fully initialized, the "Status check" will show "2/2 checks passed". The instance will be ready to use.
    Checks Passed
  • Check the box next to your Ubuntu Server instance. (If you have more than one instance, be sure that only this instance is checked.) At the top of the page, click the Connect button.
    Check and Connect
  • Use the EC2 Instance Connect.
    Connect
  • Leave ubuntu entered for the username.
  • Ignore any AWS console warnings. These warnings occur because the Learner Lab restricts access to some of the instant status checks.
  • Click Connect.
  • A new browser tab will open with a command-line interface.
    CLI

Essentially, AWS has created an SSH connection to your virtual machine, and is serving that connection through your web browser.

Explore the Ubuntu Server

Run the following commands in the terminal and explore the output.

pwd
whoami
ls -al
cd /
ls
cd ~
pwd

You should see output similar to the following.

ubuntu@ip-172-31-50-60:~$ pwd
/home/ubuntu
ubuntu@ip-172-31-50-60:~$ whoami
ubuntu
ubuntu@ip-172-31-50-60:~$ ls -al
total 28
drwxr-x--- 4 ubuntu ubuntu 4096 Jul  1 16:11 .
drwxr-xr-x 3 root   root   4096 Jul  1 16:08 ..
-rw-r--r-- 1 ubuntu ubuntu  220 Mar 31 08:41 .bash_logout
-rw-r--r-- 1 ubuntu ubuntu 3771 Mar 31 08:41 .bashrc
drwx```-- 2 ubuntu ubuntu 4096 Jul  1 16:11 .cache
-rw-r--r-- 1 ubuntu ubuntu  807 Mar 31 08:41 .profile
drwx```-- 2 ubuntu ubuntu 4096 Jul  1 16:08 .ssh
ubuntu@ip-172-31-50-60:~$ cd /
ubuntu@ip-172-31-50-60:/$ ls
bin  bin.usr-is-merged  boot  dev  etc  home  lib  
lib.usr-is-merged  lib64  lost+found  media  mnt  
opt  proc  root  run  sbin  sbin.usr-is-merged  snap
  srv  sys  tmp  usr  var
ubuntu@ip-172-31-50-60:/$ cd ~
ubuntu@ip-172-31-50-60:~$ pwd
/home/ubuntu
ubuntu@ip-172-31-50-60:~$ 

Linux administrators use the command line interface to use applications and configure the systems. You will learn how to use Linux in future lessons.

Stopping Your Ubuntu Server Instance

When you are finished with your Ubuntu Server EC2 instance, you can stop it to avoid per-hour charges. (Note that a nominal charge will still apply for the storage of the virtual machine.)

  • Close the browser tab with the Ubuntu command-line interface.
  • Return to the AWS Management Console.
  • At the top of the page, click EC2, then use either of the Instances links.
    Access Running Instances
  • Check the box next to your Ubuntu Server instance. (If you have multiple instances, ensure that only the one Ubuntu Server instance is selected.) At the top of the page, click Instance State, and then click Stop. Confirm that you want to stop the instance.
    Stop Instance

Stopping an instance does not delete it. Stopping an instance is like shutting down a computer. The computer still exists in its shut down state.

Reconnecting

If you start your Ubuntu Server EC2 instance later, it will be assigned a different public IP address but the same connection method will continue to work. Here are summarized steps for connecting to the Ubuntu Server EC2 instance after having stopped your instance.

  • Open the AWS Management Console.
  • Access the EC2 dashboard.
  • Open the Instances link.
  • Check the box next to your Ubuntu Server instance.
  • Click Instance State, then click Start.
  • Return to the list of instances to check the instance's status. Refresh the status periodically. It will take several minutes for the EC2 instance to start.
  • When the status checks show that all checks have passed, check the instance's box, and click Connect.
  • Use the EC2 Instance Connect method to connect.
  • You should now have a command line interface.
  • When finished working with your server, you can stop the instance in the AWS Management Console.

Learning Checkpoint

By this point you should be able to:

  • Access the AWS Management Console.
  • Launch an Ubuntu Server EC2 instance in AWS.
  • Check the status of EC2 instances.
  • Connect to the command-line interface using EC2 Instance Connect.
  • Stop EC2 instances.
  • Start EC2 instances.