AWS Series -2 | Remote Access an EC2 Instance with or without SSH

Introduction to AWS Series
Learning a new technology can be challenging, so I’m creating this AWS series to help people dedicate just 10 minutes a day to learning something valuable. Over time, these small lessons will add up to a fully-fledged skill set.
Note: We’ll mostly rely on free resources for this series.
Recap
In the previous article, we covered how to create an EC2 instance. Today, we’ll go over how to remotely access the same EC2 instance from your local machine or even from AWS console and explore some basic commands.
Tip: If you haven’t read the previous article, I recommend reviewing it first to follow along more easily.
Steps To Remotely Access EC2 Instance
- Open Terminal and Navigate To The .pem File Location
Open your terminal and navigate (cd) to the folder where your.pemfile is downloaded. - Get the Public DNS of Your EC2 Instance
- Go to the EC2 dashboard in your AWS console.
- Click on your EC2 instance.
- Click on Connect.
- Under SSH client, locate the Public DNS.
3. Run the SSH Command
Use the following command to connect to your EC2 instance:
ssh -i <ec2-key-pair-filename.pem> ubuntu@<public_dns>- Replace
<ec2-key-pair-filename.pem>with the actual name of your.pemfile. - Replace
<public_dns>with the Public DNS of your EC2 instance.
Note: Adjust the username based on the OS or Linux distribution you selected:
- Ubuntu:
ubuntu - Amazon Linux / Amazon Linux 2:
ec2-user - CentOS:
centos - RHEL:
ec2-userorroot - Debian:
adminorroot - SUSE Linux:
ec2-userorroot
After running the command, you’ll be prompted with, “Are you sure you want to continue?” Press yes to access your remote machine.
Basic Commands
Here are some essential commands to know about your EC2 instance:
- Get OS details:
cat /etc/os-release - Check memory:
free -m - View CPU count:
lscpu - Retrieve IP address:
ip a - Login as a root user:
sudo -i
Accessing an EC2 Instance Without SSH
If you don’t have an SSH client, you can use Git Bash instead.
- Install Git Bash (if not already installed).
- Open Git Bash.
- Navigate (
cd) to the folder where your.pemfile is downloaded. - Run the same SSH command to access the instance.
Accessing via Browser
- Login to your AWS Account.
- Go to EC2 Dashboard.
- Select your EC2 instance and click on Connect.
- Under EC2 Instance Connect, click Connect again.
A terminal will open, allowing you to use the machine directly through your browser.
Queries and Doubts
Thanks for the read :) Hope you have enjoyed reading it 🤩 and learnt something new today.
If you have any doubts or queries feel free to drop a comment or
⁍ Connect with me on my 🔗Topmate 💬.
⁍ You can also reach out to me on my 🔗LinkedIn.
⁍ Please do clap for this post if you enjoyed reading it 📗 and follow for more interesting articles.
⁍ You can also support me and my writings by treating me to a nice virtual cup of coffee ☕️.