Accessing AWS EC2 Instances

In the previous post, we explored how to create an EC2 instance in AWS. Now, let's learn how to access it securely using different methods on Windows, Linux, and even directly from your browser.

Accessing EC2 from Windows 10 (and Above)

Windows 10 and later versions come with built-in SSH support, making it easy to access your EC2 instance. Follow these steps:

  1. Navigate to the Location of Your Key Pair:

    • Open the folder where you downloaded the .pem file for your instance key pair.
    • Right-click within the folder and select Open in Terminal or type cmd in the folder path to open Command Prompt in that directory.
  2. Run the SSH Command: Use the following command structure:

    ssh -i <key_file_name>.pem ubuntu@<public_dns>
    

    Example:

    ssh -i youtube-key.pem ubuntu@ec2-18-223-45-12.compute-1.amazonaws.com
    
    • Replace <key_file_name>.pem with your key file name.
    • Replace <public_dns> with the public DNS or IP of your EC2 instance.
  3. Confirm the Connection:

    • When prompted, type yes to accept the host key fingerprint.
    • You are now logged into your EC2 instance.

Accessing EC2 from Older Versions of Windows

For Windows versions without built-in SSH:

  1. Install Git Bash:

  2. Navigate to the Key Pair Location:

    • Use the cd command to move to the folder containing the .pem file.
  3. Run the SSH Command:

    • Use the same SSH command mentioned above.

Accessing EC2 from Linux

Linux systems have native SSH support. Here’s how to access your instance:

  1. Open Terminal:

    • Use the cd command to navigate to the folder where the .pem file is stored.
  2. Change File Permissions (If Required):

    chmod 400 <key_file_name>.pem
    
  3. Run the SSH Command:

    ssh -i <key_file_name>.pem ubuntu@<public_dns>
    
  4. Confirm the Connection:

    • Type yes if prompted to accept the host key fingerprint.

Browser-Based Access Using AWS Management Console

For users who prefer browser-based access:

  1. Log in to the AWS Console.
  2. Navigate to EC2 Instances:
    • Select your instance and click Connect.
  3. Choose Browser-Based SSH:
    • Under the "Session Manager" or "EC2 Instance Connect" tab, click Connect.
  4. Access Your Instance:
    • The browser-based terminal opens, allowing you to manage the instance without additional tools.

Verifying Your Instance Configuration

After accessing your EC2 instance, verify the setup by running the following commands:

  1. Check the Operating System:

    cat /etc/os-release
    

    Example Output:

    Ubuntu 22.04 LTS
    
  2. Check Memory:

    free -m
    

    Example Output:

    Total: 1GB RAM
    
  3. Check CPU:

    lscpu
    

    Example Output:

    CPUs: 1 Core
    
  4. Check Network Configuration:

    ip a
    

    Example Output:

    • Public and Private IP addresses.

Avoiding Overloaded Availability Zones

AWS manages availability zones intelligently to balance resources. However, users often unknowingly select the default zone, potentially leading to overcrowding. To ensure balanced distribution:

  • Explicitly specify the availability zone when launching instances.
  • AWS maps zones uniquely for each account, so what appears as us-east-1a for one user may differ for another.

Accessing your EC2 instance is straightforward with the right tools and configurations. Whether you use SSH from Windows, Linux, or a browser-based solution, AWS provides multiple options for seamless instance management. By understanding these methods, you can ensure secure and efficient access to your cloud resources.

Stay tuned for more advanced configurations and practical use cases. For additional tutorials, visit Learning Ocean.