
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
The AWS console has hundreds of services, and the first time you open EC2 the wizard throws AMIs, instance types, key pairs, and security groups at you before you have launched anything. This guide on AWS EC2 for beginners cuts that noise down to the decisions that matter: pick the right image and size, create a key pair you will not lock yourself out with, open only the ports you need, connect over SSH, pin a stable address with an Elastic IP, and harden the box before it faces the internet. If you would rather have the whole stack built and secured for you, the cloud and DevOps deployment services cover exactly this.
ssh -i key.pem ubuntu@your-ip and harden it.What do you need before launching your first EC2 instance?
EC2 (Elastic Compute Cloud) is a virtual server you rent by the second. Before you click Launch, it helps to know the four building blocks the wizard asks about, because each one is a separate decision:
- AMI (Amazon Machine Image) — the operating system template the instance boots from. For a first server, pick Ubuntu Server 24.04 LTS; it is free-tier eligible, well documented, and long-term supported.
- Instance type — the CPU and memory size. A
t3.micro(2 vCPU, 1 GB) is a fine starting point and is covered by the free tier in most regions; resize later without rebuilding. - Key pair — the SSH credential. AWS keeps the public key and gives you the private
.pemfile once. Lose it and you lose SSH access to that instance. - Security group — a stateful firewall attached to the instance that decides which inbound ports are open.
You also want a region close to your users (for example ap-south-1 in Mumbai for a Nepal or South Asia audience) so latency stays low.
How do you create a key pair and launch the instance?
The key pair is where most beginners trip up, so create it first. In the console go to EC2 → Key Pairs → Create key pair, choose the ED25519 type and .pem format, and your browser downloads the private key once. You can also do the whole thing from the AWS CLI, which is worth learning early:
aws ec2 create-key-pair \
--key-name my-first-key \
--key-type ed25519 \
--query 'KeyMaterial' \
--output text > my-first-key.pem
chmod 400 my-first-key.pem The chmod 400 matters — SSH refuses to use a key file that other users can read. Now launch an instance against that key, an Ubuntu AMI, and a security group (created in the next section). Using the CLI keeps the choices explicit:
aws ec2 run-instances \
--image-id resolve:ssm:/aws/service/canonical/ubuntu/server/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id \
--instance-type t3.micro \
--key-name my-first-key \
--security-group-ids sg-0abc123def4567890 \
--block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":20,"VolumeType":"gp3"}}]' \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=my-first-server}]' That resolve:ssm: path asks AWS for the latest official Ubuntu 24.04 AMI in your region, so you never paste a stale image ID. The block-device mapping gives the root EBS volume 20 GB of gp3 storage — more on EBS below.
How should you configure the security group for a new server?
A security group is the single most important control between your server and the internet. The rule that keeps beginners safe: open SSH (port 22) only to your own IP address, never to 0.0.0.0/0. Web ports can be open to everyone, because that is the point of a web server.
Create the group and add exactly three inbound rules from the CLI (replace 203.0.113.10 with your public IP, which you can find at checkip.amazonaws.com):
SG_ID=$(aws ec2 create-security-group \
--group-name my-first-sg \
--description "First EC2 server" \
--query 'GroupId' --output text)
aws ec2 authorize-security-group-ingress --group-id "$SG_ID" \
--protocol tcp --port 22 --cidr 203.0.113.10/32
aws ec2 authorize-security-group-ingress --group-id "$SG_ID" \
--protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id "$SG_ID" \
--protocol tcp --port 443 --cidr 0.0.0.0/0 Security groups are stateful and deny by default: you only list what to allow inbound, and matching return traffic is permitted automatically. There is no need to add outbound rules for normal use. If your home IP changes often, update the port-22 rule rather than widening it to the whole internet.
How do you SSH in and assign an Elastic IP?
Once the instance shows running, connect with the private key and the default Ubuntu username. The first login also confirms your security group and key pair are correct:
ssh -i my-first-key.pem [email protected] There is a catch: a plain instance gets a public IP that changes every time you stop and start it. For anything you will point a domain at, allocate an Elastic IP — a static public address — and associate it with the instance so the address stays put:
EIP_ALLOC=$(aws ec2 allocate-address --query 'AllocationId' --output text)
aws ec2 associate-address \
--instance-id i-0abc123def4567890 \
--allocation-id "$EIP_ALLOC" An Elastic IP is free while it is attached to a running instance, but AWS charges a small hourly fee for one that is allocated and left unused — so release any you no longer need. If you plan to put a real application here next, the guide to hosting a Laravel app on AWS EC2, RDS and S3 picks up right where this leaves off.
How do you secure a fresh EC2 instance?
A brand-new instance is reachable and unpatched, so harden it before installing anything else. These first steps apply to any Ubuntu server, and the initial Ubuntu server setup guide covers the same hardening in more depth for any VPS:
- Patch immediately —
sudo apt update && sudo apt upgrade -ycloses known holes on first boot. - Create a non-root sudo user and stop working as the default account for day-to-day tasks.
- Disable password authentication so only your key can log in.
- Enable a host firewall with UFW as a second layer behind the security group.
- Add Fail2ban to throttle brute-force SSH attempts.
sudo apt update && sudo apt upgrade -y
sudo adduser deploy
sudo usermod -aG sudo deploy
sudo rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy
sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' \
/etc/ssh/sshd_config
sudo systemctl restart ssh
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw --force enable
sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban Open a second SSH session as the new deploy user to confirm key login works before you close the original one — locking yourself out of a hardened box is a rite of passage worth skipping.
What is EBS, and what is the difference between stop and terminate?
Your instance's disk is an EBS (Elastic Block Store) volume — network-attached storage that lives independently of the instance's compute. That separation drives the two actions beginners most often confuse:
- Stop — powers the instance off. Compute billing pauses, but the EBS volume is kept, so your data and installed software survive. You keep paying for the EBS storage (and any unattached Elastic IP). Start it again and everything is as you left it.
- Terminate — permanently deletes the instance. By default the root EBS volume is deleted with it, so the data is gone unless you took a snapshot. This is irreversible.
For cost control, stop instances you are only using occasionally rather than leaving them running, and take an EBS snapshot before any risky change so you can restore. Snapshots are cheap incremental backups stored in S3 behind the scenes. Only terminate when you are certain you want the server and its disk gone for good.
Conclusion
Launching your first AWS EC2 instance comes down to a short, repeatable checklist: pick an Ubuntu AMI and a t3.micro, create and protect a key pair, allow SSH only from your IP, attach an Elastic IP, then patch and harden before you serve any traffic. Understand EBS and the stop-versus-terminate distinction and you will avoid both surprise bills and accidental data loss. When you are ready to run a real application on this foundation, browse the AWS deployment case studies to see the pattern in production, or get in touch to have your EC2 environment built and secured for you.