Security Groups for Beginners

Beginner
10 min read
Updated: Nov 2026
4 steps
Console walkthrough

What Is a Security Group?

An AWS security group is a virtual firewall for your EC2 instance (and for other network interfaces). Think of it as a door list for network traffic.

You write rules that say what is allowed in or out:

  • Inbound — who can start a connection to your instance (SSH, HTTP, HTTPS…).
  • Outbound — where your instance may start connections (often “all” by default).
  • Deny by default (inbound) — if a port is not listed, outsiders cannot open it.
Beginner tip.

Security groups have no extra fee. Wrong rules are the #1 reason a new website on EC2 “won’t load.”

In Simple Words

What problem does it solve?

An instance on the internet can receive traffic from anyone. Security groups let you allow only the ports you need—for example SSH for you, HTTP for visitors—and block the rest.

Is a security group the same as a password?

No. Keys and passwords prove who you are after the connection starts. A security group decides whether the connection is allowed to reach the instance at all.

When should a beginner use it?

Every time you launch an EC2 instance, deploy Node / Express, put Nginx on port 80, or place an Application Load Balancer in front of targets.

A tiny traffic picture

Visitor → internet → security group check → EC2 (or ALB) → your app. If the inbound rule is missing, the browser times out even when Node is running.

Stateful shortcut.

You usually do not need a special outbound rule for replies to allowed inbound traffic. AWS tracks the connection.

Want the official page?

Read Amazon EC2 security groups in the AWS docs.

Words You Will See

Come back when the console shows a new word.

WordPlain meaning
Inbound ruleAllows traffic coming to the instance on a protocol/port from a source
Outbound ruleAllows traffic leaving the instance to a destination
Type / PortShortcuts like SSH (22), HTTP (80), HTTPS (443), or a custom TCP port
SourceWho may connect: a CIDR (e.g. 0.0.0.0/0), My IP, or another security group
0.0.0.0/0Anywhere on the IPv4 internet
StatefulAllowed connections get reply traffic without a matching reverse rule
Default security groupUsed if you pick none at launch; often too open or too closed for demos—create your own

What You Need First

  • An AWS account and access to the EC2 console in your Region.
  • An instance (or a plan to launch one) in a VPC—see Launch an EC2 instance.
  • A short list of ports you need (SSH 22, HTTP 80, HTTPS 443, or your app port such as 3000).

Step-by-Step

Four small steps: create a group, add beginner rules, attach it, then verify.

Step 1 — Create a Security Group

Give yourself a named door list instead of relying only on the VPC default.

  1. Open the AWS console → EC2.
  2. Under Network & Security, choose Security Groups.
  3. Choose Create security group.
  4. Set a clear name (for example web-demo-sg) and description.
  5. Select the same VPC as your instance.

How It Works

  1. A security group lives in one VPC—it cannot span Regions or unrelated VPCs.
  2. Empty inbound rules mean no public connections until you add them.
  3. You can attach the same group to many instances that share the same door policy.

Step 2 — Add Beginner Inbound Rules

Typical first website on a single EC2 instance:

  1. SSH — TCP 22, source My IP (preferred) or a known CIDR.
  2. HTTP — TCP 80, source 0.0.0.0/0 if the site must be public.
  3. HTTPS — TCP 443, source 0.0.0.0/0 when you serve TLS on the instance.
  4. If your app listens on 3000 without Nginx, open TCP 3000 instead of (or until you add) 80.
EC2 network settings showing SSH HTTP HTTPS security group options
Amazon EC2

How It Works

  1. Each rule is an allow—security groups do not have “deny this IP” lines the way some firewalls do.
  2. Source can be another security group—perfect for ALB → EC2 (allow the ALB’s group, not the whole internet, on the app port).
  3. Outbound defaults usually allow all; tighten later if your policy requires it.
Least privilege for SSH.

Tutorials often open SSH to everywhere. Switch SSH to My IP as soon as you can.

Step 3 — Attach the Group to Your Instance

Rules only help if the instance uses this group.

  1. Open Instances, select your instance.
  2. Choose Actions → Security → Change security groups (wording can vary slightly).
  3. Add web-demo-sg (and remove groups you do not want).
  4. Save. Changes apply without relaunching the instance.

How It Works

  1. An instance can have multiple security groups—AWS evaluates the combined allows.
  2. Editing rules later updates every attached instance automatically.
  3. Launch wizard can create or select a group up front—same idea as attaching afterward.

Step 4 — Verify SSH and HTTP

  1. SSH with PuTTY or OpenSSH using your key and the public IP / Elastic IP.
  2. If a web app or Nginx listens on 80, open http://YOUR_IP/ in a browser.
  3. If SSH works but HTTP fails, confirm the process is listening and that TCP 80 (or 3000) is in the inbound rules.
  4. Behind an ALB: open 80/443 on the ALB group; on the instance, allow the ALB security group on the target port.
Application Load Balancer security group selection in the console
Elastic Load Balancing

How It Works

  1. Two doors for ALB setups—client → ALB, then ALB → instance.
  2. Timeouts often mean a closed port; connection refused often means nothing is listening.
  3. After Nginx owns 80, you can close public access to the app’s high port.

Common Beginner Mistakes

App runs, browser times out

Node is fine; inbound HTTP/HTTPS (or 3000) is missing. Open the matching port.

Wrong port for the app

Security group allows 80 but the process listens on 3000 (or the reverse).

SSH open to the world forever

Use My IP for TCP 22 when you are done with the first demo.

Only opening the instance for an ALB site

Clients hit the ALB first. The ALB security group needs 80/443 too.

Allowing 0.0.0.0/0 to targets behind an ALB

Prefer source = the ALB security group on the app/health-check port.

Editing the wrong Region’s group

Security groups are Regional. Check the console Region matches the instance.

Key Takeaways

  • Security groups are allow-lists for inbound (and outbound) traffic.
  • They are stateful—replies to allowed connections are tracked automatically.
  • Match ports to the app (22 / 80 / 443 / 3000) and tighten SSH sources.
  • ALB setups need two layers of rules: clients→ALB and ALB→targets.

One line: open only the ports you need, prefer My IP for SSH, and remember the ALB door if you use a load balancer.

Frequently Asked Questions

A security group is a virtual firewall for EC2 instances (and other ENIs) that allows traffic you list in inbound and outbound rules; everything else is denied by default for inbound traffic.
Yes. There is no extra charge for using security groups. You still pay for the resources they protect, such as EC2 instances.
If an inbound connection is allowed, the reply traffic is allowed out automatically. If your instance starts an outbound connection that is allowed, the reply can come back in without a matching inbound rule.
Only for quick demos. Prefer My IP (or a known office CIDR) for SSH. Opening SSH to the whole internet makes password or key guessing attacks more likely.
Yes. The ALB needs inbound rules for client ports (often 80/443). Targets need inbound rules that allow traffic from the ALB security group on the app and health-check ports.
Yes. You can edit rules anytime, and you can change which security groups are attached to a running instance. New rules apply to associated instances automatically.

Next: Elastic IP for EC2

Keep a stable public IPv4 so SSH and DNS do not break after stop/start.

Elastic IP for EC2 →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful