Connecting to Your Amazon EC2 Instance: A Step-by-Step Guide


In my previous post, I discussed how to create an Amazon EC2 instance. Now, I’ll walk you through a streamlined method to connect to your instance using EC2 Instance Connect. This feature simplifies the process of connecting to your instances without the need to manage SSH keys manually.

What is EC2 Instance Connect?

EC2 Instance Connect allows you to securely connect to your EC2 instances using a browser-based SSH client. This eliminates the need for a local SSH client and simplifies key management, especially for temporary connections.

Prerequisites

Before connecting, ensure the following:

  • EC2 Instance Running: Your instance should be in a running state.

  • Instance Type: EC2 Instance Connect is supported on Amazon Linux 2 and Ubuntu 20.04 and later instances.

Step-by-Step Guide to Connect via EC2 Instance Connect

Step 1: Open the EC2 Console

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 Dashboard.

Step 2: Select Your Instance

  1. In the EC2 console, click on Instances in the left-hand menu.

Locate and select the instance you wish to connect to.

Step 3: Connect Using EC2 Instance Connect

  1. With your instance selected, click on the Connect button at the top of the instance details page.

  1. In the Connect to instance dialog, select the EC2 Instance Connect tab.

Step 4: Configure Connection Settings

  1. User Name: Choose the appropriate username based on your instance type. Common usernames include:

    • For Amazon Linux 2: ec2-user

    • For Ubuntu: ubuntu

    • For CentOS: centos

  2. Connect: Click the Connect button.

What Happens After You Connect?

Once you’re connected to your Ubuntu instance via the browser-based terminal, you can start running commands to configure and manage your server. Let’s walk through some basic commands you can execute to get your instance ready for use.

Step 1: Clear the Terminal (Optional)

When you first connect, your terminal may display a lot of information. To start with a clean slate, you can clear the terminal by using the clear command:

clear

Step 2: Update the System

Before installing any new software, it’s a good practice to update your system to ensure you have the latest security patches and software updates. Run the following command:

sudo apt-get update

Step 3: Install NGINX

Now that your package list is updated, you can install NGINX, a powerful web server used to serve websites and handle web traffic efficiently.

To install NGINX, run the following command:

sudo apt-get install nginx

Sep 4: Navigate to the Web Directory

Once NGINX is installed, the default web directory where NGINX serves web content is located in /var/www/html. Let’s navigate to this directory:

In your terminal, type the following command to change to the NGINX default directory:

cd /var/www/html

Sep 5: Create a New Web Page using NGINX

Now, let’s create your own HTML file using the nginx

  1. Open a new file in Vim by running:

     vim index.html
    
    1. Press i to enter Insert Mode in Vim, allowing you to start typing. Add the following simple HTML code to display a heading on your web page:
    <h1> Welcome to My First NGINX Web Page </h1>
    <p> This is sample HTML example served by NGINX on an Ubuntu EC2 instance </p>

Step 3: Save and Exit Vim

  1. After typing the content, press Esc to exit Insert Mode.

  2. Type :wq to save the file and exit Vim.

  3. If it dont allow to read then go back and give sudo vim index.html and sudo systemctl restart nginx.

  4. Copy the Public IP address and paste in new Open new browser by adding colon 80 web page is running i.e.,

  5. That’s it! You’ve just created your first web page on an Ubuntu EC2 instance running NGINX. By following these simple steps, you can now create and serve your own HTML content directly from the cloud.

  1. Here are some common port numbers and their uses:

    1. Port 22:

      • Service: SSH (Secure Shell)

      • Usage: Remote login and command-line access to servers securely.

    2. Port 80:

      • Service: HTTP (HyperText Transfer Protocol)

      • Usage: Default port for serving unencrypted web pages over the internet.

    3. Port 443:

      • Service: HTTPS (HTTP Secure)

      • Usage: Default port for serving encrypted web pages using SSL/TLS.

    4. Port 25:

      • Service: SMTP (Simple Mail Transfer Protocol)

      • Usage: Used for sending emails.

    5. Port 21:

      • Service: FTP (File Transfer Protocol)

      • Usage: Used for transferring files between systems.

    6. Port 53:

      • Service: DNS (Domain Name System)

      • Usage: Resolves domain names to IP addresses.

    7. Port 3306:

      • Service: MySQL Database

      • Usage: Default port for MySQL database connections.

    8. Port 1433:

      • Service: Microsoft SQL Server

      • Usage: Default port for MS SQL Server database connections.

    9. Port 8080:

      • Service: HTTP Alternative

      • Usage: Often used as an alternative HTTP port for development or testing environments.

    10. Port 3389:

  • Service: RDP (Remote Desktop Protocol)

  • Usage: Used for remote desktop connections to Windows servers.

These are some of the key port numbers used for different services in networking and system administration.

1
Subscribe to my newsletter

Read articles from sravani punreddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sravani punreddy
sravani punreddy