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:
-
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.
- Open the folder where you downloaded the
-
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.
- Replace
-
Confirm the Connection:
- When prompted, type
yes
to accept the host key fingerprint. - You are now logged into your EC2 instance.
- When prompted, type
Accessing EC2 from Older Versions of Windows
For Windows versions without built-in SSH:
-
Install Git Bash:
- Download Git Bash from the official website.
- Install and open Git Bash.
-
Navigate to the Key Pair Location:
- Use the
cd
command to move to the folder containing the.pem
file.
- Use the
-
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:
-
Open Terminal:
- Use the
cd
command to navigate to the folder where the.pem
file is stored.
- Use the
-
Change File Permissions (If Required):
chmod 400 <key_file_name>.pem
-
Run the SSH Command:
ssh -i <key_file_name>.pem ubuntu@<public_dns>
-
Confirm the Connection:
- Type
yes
if prompted to accept the host key fingerprint.
- Type
Browser-Based Access Using AWS Management Console
For users who prefer browser-based access:
- Log in to the AWS Console.
- Navigate to EC2 Instances:
- Select your instance and click Connect.
- Choose Browser-Based SSH:
- Under the "Session Manager" or "EC2 Instance Connect" tab, click Connect.
- 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:
-
Check the Operating System:
cat /etc/os-release
Example Output:
Ubuntu 22.04 LTS
-
Check Memory:
free -m
Example Output:
Total: 1GB RAM
-
Check CPU:
lscpu
Example Output:
CPUs: 1 Core
-
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.