Launch Your First EC2 Linux Instance
Launch your first EC2 Linux instance — hands-on AWS Tutorial lesson covering core concepts, step-by-step setup, troubleshooting, and next steps.
Focus: launch your first ec2 linux instance
You've set up your AWS account, secured it with IAM, and maybe even touched S3 — but now the real work begins. Every production Python backend eventually needs a permanent home: a server that runs your code 24/7, scales with your traffic, and doesn't care if your laptop is closed. That's where Amazon EC2 comes in. In this lesson, you'll launch your first EC2 Linux instance from zero to SSH-ready, and by the end you'll have a running virtual server that you can deploy Django, FastAPI, or Flask to in the very next step.
The problem this lesson solves
When you develop locally, your code runs on your machine. But the moment you share a link, your localhost is useless. You need a remote server that:
- Runs your Python app 24/7, even when your machine is asleep.
- Has a public IP address so users can reach it.
- Can scale up (or down) as demand changes.
- Is managed by a cloud provider so you don't buy hardware.
EC2 is AWS's core compute service. It gives you virtual machines — instances — in the cloud. You pick an operating system (including various Linux distros), choose the CPU/memory combo, and launch in minutes. But first-time users often get stuck on:
- Choosing the right AMI (Amazon Machine Image)
- Configuring a key pair for SSH
- Setting up the security group correctly
This lesson removes that friction. You'll launch your first EC2 Linux instance and SSH into it, ready for real deployments.
Real-world pain: Skipping security group setup means your instance is exposed to the entire internet. A wrong key pair means you can't log in at all. Get these right now and you'll save hours later.
Core concept / mental model
Think of EC2 as a rented computer in a remote data center. You pick the hardware (CPU, RAM, storage), the software (Linux + your app), and the network rules. You pay only for what you use, by the second.
The key components you'll configure during launch:
- AMI (Amazon Machine Image) — the operating system template. For this lesson, we'll use Amazon Linux 2023, which is optimized for AWS and supports Python 3.9+ out of the box.
- Instance type — the hardware specs.
t2.microort3.microare free-tier eligible and plenty for learning. - Key pair — a cryptographic key that lets you SSH in securely. AWS stores the public half; you keep the private
.pemfile. - Security group — a virtual firewall that controls inbound/outbound traffic. You'll open port 22 (SSH) to your IP.
- Elastic IP (optional) — a static public IP so your instance address doesn't change after reboot.
[Your Laptop] --SSH--> [EC2 Instance: t3.micro, Amazon Linux 2023]
|
\--> [Security Group: allow 22 from your IP]
How it works step by step
Here's the logical flow from AWS Console to a usable server:
- Log in to the AWS Management Console and go to EC2.
- Choose an AMI — select
Amazon Linux 2023 AMI(64-bit, x86). This gives you a minimal, stable Linux server. - Pick an instance type — choose
t3.micro(free tier eligible). It has 2 vCPUs and 1 GiB RAM, enough for a small Python app. - Configure key pair — create a new key pair, name it (e.g.,
my-first-ec2), download the.pemfile. Store it safely — you can't download it again. - Set network settings — let AWS create a default VPC. Enable 'Allow SSH traffic from' your IP (not
0.0.0.0/0). - Add storage — use the default 8 GiB gp2/gp3 root volume. That's plenty for learning.
- Launch instance — review and click Launch. AWS will start your instance within minutes.
- Connect — once the instance is
Running, use the Connect button in the console or runsshfrom your terminal.
Pro tip: Use the t3.micro type if you're in the free tier. If not,
t2.microis almost always cheaper. You can change types later, but you'll need to stop the instance first.
Hands-on walkthrough
Now let's do it for real. Follow these steps in the AWS Console.
Step 1: Launch Instance via Console
- In the AWS Console, search for EC2 and open it.
- Click Launch instance (blue button).
- Under Name, enter
my-first-ec2. - Under Application and OS Images (Amazon Machine Image), click Quick Start and choose Amazon Linux 2023 AMI (Free tier eligible).
- Under Instance type, select
t3.micro(ort2.micro). - Under Key pair (login), click Create new key pair. Name it
my-first-key, leave RSA,.pemformat. Download it — you'll need it to SSH. - Under Network settings, click Edit. Ensure a VPC is selected (default is fine). In Firewall (security groups), select Create security group. Name it
my-ec2-sg. Add a rule: typeSSH, source My IP (AWS shows your current public IP). - Under Configure storage, keep the default 8 GiB gp3.
- Click Launch instance.
You'll see a success message. Click View all instances to see your instance booting up.
Step 2: Connect via SSH
Once the instance state is Running, you can SSH from your terminal.
On macOS/Linux:
chmod 400 my-first-key.pem
ssh -i my-first-key.pem ec2-user@<public-ip>
On Windows (PowerShell):
ssh -i my-first-key.pem ec2-user@<public-ip>
Replace <public-ip> with the IPv4 address shown in the EC2 console. You'll see a welcome banner and a command prompt:
[ec2-user@ip-... ~]$
Tip: If you get a permission error, make sure you
chmod 400the key file. On Windows, you might need to use WSL or PuTTY.
Step 3: Verify Python and Update System
Inside the instance, run:
sudo yum update -y
python3 --version
Expected output (or similar):
Python 3.9.16
If you want a newer Python (e.g., 3.11), you can install it later, but 3.9 is enough for most tutorials.
Compare options / when to choose what
Instance types: burstable vs. general purpose
| Instance type | Free tier? | vCPUs | RAM | Best for |
|---|---|---|---|---|
t2.micro |
Yes | 1 | 1 GiB | Learning, low-traffic apps |
t3.micro |
Yes (in some regions) | 2 | 1 GiB | Better CPU burst, same price |
t4g.micro |
Yes | 2 | 1 GiB | ARM-based, cheaper if workloads support |
For this course, stick with t3.micro or t2.micro. If you're on the free tier, both work.
AMI choices
- Amazon Linux 2023 — best integration with AWS, frequent updates, optimized for performance.
- Ubuntu 22.04 — more familiar to many developers, large community.
- Alpine — tiny, but not ideal for production Python due to compatibility quirks.
We chose Amazon Linux because it's the default when you're learning AWS, and it has the ec2-user default user.
Alternative: use EC2 Instance Connect
Instead of SSH from your terminal, you can click Connect in the console and use the browser-based terminal. This works even if you lost your key pair — but it requires you to enable IAM permissions. For learning, SSH is the standard.
Troubleshooting & edge cases
Here are the most common issues you'll hit:
Permission denied (publickey)
- Wrong key pair — ensure you're using the
.pemfile associated with this instance. - Key permissions too open — run
chmod 400 my-first-key.pemon Linux/macOS. - Wrong username — Amazon Linux uses
ec2-user, notubuntuorroot.
SSH timeout
- Your security group doesn't allow inbound SSH from your IP. Go to EC2 > Security Groups, edit inbound rules, add SSH from your current IP.
- The instance is still booting — wait 30 seconds and retry.
- Your IP might have changed (e.g., on home Wi-Fi) — update the security group rule.
Instance is running, but no internet from it
- Check that your VPC has an Internet Gateway. If you used the default VPC, it should already be attached. If not, you'll need to attach one.
- Did you enable Auto-assign public IP? If not, your instance has no public IP. You can allocate an Elastic IP and associate it.
Can't ping the instance
ICMP (ping) is not enabled by default. Add a custom TCP rule for port 8 (echo request) if you want to test connectivity, but SSH is enough.
Lost your key pair?
- You can't recover it, but you can use EC2 Instance Connect (if available) or stop the instance, detach its root volume, mount it on another instance, and modify the authorized_keys — advanced, and beyond this lesson.
What you learned & what's next
You've successfully launched your first EC2 Linux instance — a fundamental skill for any AWS developer. Now you can:
- Explain the core components: AMI, instance type, key pair, security group.
- Apply that knowledge to launch a server in minutes.
- Connect via SSH and run commands on a remote Linux system.
What's next: In the next lesson, you'll deploy a small Python HTTP server or a simple FastAPI app to this instance. You'll use scp or git to upload your code, then use systemd or gunicorn to keep your app running. That's where the real backend work begins.
Remember to terminate your instance when you're done to avoid charges — find it in the EC2 console, select it, and click Actions > Instance state > Terminate.
Final pro tip: Always read the instance's public IP from the console. If you stop and start the instance later, the IP may change. Use an Elastic IP if you need a stable address for production.
Practice recap
Now that you've launched your first EC2 instance, try a quick exercise: SSH in and run sudo yum update -y, then install Python's pip with sudo yum install -y python3-pip and create a simple hello.py that prints a message. Run it to confirm your server works. Next lesson, you'll turn this into a running web service.
Common mistakes
- Using the wrong SSH username — Amazon Linux uses
ec2-user, Ubuntu usesubuntu, and many users tryrootand get a permission error. - Forgetting to set restrictive permissions on the key file:
chmod 400 my-key.pemis required on Linux/macOS, otherwise SSH refuses the key. - Opening the security group to
0.0.0.0/0— this exposes SSH to the whole world, risking brute-force attacks. Always restrict to your IP. - Not waiting for the instance to be in the
Runningstate before trying to connect — it can take 20–60 seconds to boot.
Variations
- Use a different AMI, like Ubuntu Server 22.04 LTS, if you prefer Debian-based commands (
aptinstead ofyum). - Use the AWS CLI to launch an instance programmatically:
aws ec2 run-instances --image-id ami-... --instance-type t3.micro --key-name my-key. - Use EC2 Instance Connect from the console instead of SSH — no key file needed and works in a browser.
Real-world use cases
- Deploying a Django or FastAPI backend for a small production web app, using EC2 as the web server.
- Running a cron job or background worker that processes queues (e.g., Celery) on a dedicated instance.
- Hosting a personal Git server or file storage for a small team using EC2's persistent storage.
Key takeaways
- An EC2 instance is a virtual server; you choose OS via AMI, hardware via instance type, and access via key pair and security group.
- Always restrict SSH access to your own IP to avoid security vulnerabilities.
- The free tier supports
t3.microort2.microinstances with 1 GiB RAM, sufficient for learning and small apps. - SSH command for Amazon Linux is
ssh -i key.pem ec2-user@<public-ip>. - After launching, you can install software, deploy code, and manage the instance just like any Linux server.
- Remember to terminate your instance when done to avoid unexpected AWS charges.
Keep learning
Related tutorials, quizzes, and articles for this topic.
Discussion
Questions, corrections, and tips help everyone reading this page.
0 comments
Add a comment
No comments yet — start the thread.