πŸ”’ 5.3. Configuring EC2 Security Groups – Controlling Access to Your Instance πŸšͺ

Table of Contents

Hey Web Codders! πŸ‘‹ I’m Vikas Sankhla, your coding buddy from Web Codder, and today we’re talking about something super important: Security Groups on AWS EC2. πŸ”

Think of it like this:

πŸ‘‰ Your EC2 server is your house. 🏠
πŸ‘‰ A Security Group is the fence + gate 🚧 around your house.

It controls who can come in and out. πŸšΆβ€β™‚οΈπŸšͺ

Let’s dive in and make sure your EC2 is safe and sound. 😎


❓ What Are Security Groups?

In simple words:

A Security Group = A virtual firewall πŸ”₯ for your EC2.

It decides:

  • βœ… Who can enter (Inbound rules)
  • 🚫 Who can leave (Outbound rules)

πŸ›‘οΈ Why Are Security Groups Important?

Without security groups, your server would be wide open πŸ˜±β€”anyone could access it, attack it, or break it.

We use security groups to:

  • βœ… Keep the good guys in
  • 🚫 Keep the bad guys out

For example:

  • You want only YOU to connect via SSH (port 22).
  • But you want everyone to visit your website (port 80).

πŸ” Understanding Inbound & Outbound Rules

πŸ”‘ Rule TypeπŸšͺ What It Controls
Inbound RulesWho can connect to your EC2 (like visitors at your door πŸšͺ)
Outbound RulesWhere your EC2 can send data (like you making calls πŸ“ž)

Example:

Rule TypePortProtocolSourceWhat It Does
Inbound22TCPYour IP onlyAllows only you to SSH into EC2
Inbound80TCPAnywhere (0.0.0.0/0)Allows anyone to visit your website
OutboundAllAllAnywhereAllows EC2 to reach the internet

πŸ› οΈ Setting Security Group Rules (Step-by-Step)

1️⃣ Go to EC2 Dashboard


2️⃣ Create a New Security Group

  • Name: MyWebServerSG
  • Description: Security for my web server
  • VPC: Choose default (or your VPC)

3️⃣ Add Inbound Rules ➑️

TypeProtocolPort RangeSourceReason
SSHTCP22My IPSo only you can log in
HTTPTCP800.0.0.0/0Allow everyone to visit your site
HTTPSTCP4430.0.0.0/0Allow secure browsing

πŸ‘‰ Pro Tip: Use β€œMy IP” for SSH to keep it extra safe! πŸ”


4️⃣ Add Outbound Rules ⬅️

By default:
βœ… All traffic is allowed. (Good for most apps.)

You can tighten this later if needed.


5️⃣ Attach Security Group to EC2 πŸ–‡οΈ

  • Go to your EC2 instance
  • Click Actions > Networking > Change Security Groups
  • Select your new group βœ…

Done! πŸŽ‰


⚠️ Best Practices for EC2 Security Groups βœ…

1️⃣ Least Privilege:
Allow ONLY what’s needed. Don’t open random ports.

2️⃣ Restrict SSH:
Set SSH (port 22) to your IP only. 🚨 Never open to β€œAnywhere” (0.0.0.0/0).

3️⃣ Use Separate Groups:
One group for web traffic, another for database access.

4️⃣ Review Regularly:
Check your rules often. Clean up unused ports.

5️⃣ Avoid Overlap:
Be clearβ€”don’t have conflicting rules.


Blog Images Aws Security Groups Diagram
πŸ”’ 5.3. Configuring Ec2 Security Groups – Controlling Access To Your Instance πŸšͺ 2

1️⃣ EC2 Instance πŸ–₯️
2️⃣ Security Group πŸ”’
3️⃣ Inbound/Outbound Rules βž‘οΈβ¬…οΈ
4️⃣ Safe & Secure Hosting! πŸš€


βœ… Bonus: Common Ports Cheat Sheet

ServicePort Number
SSH22
HTTP80
HTTPS443
MySQL3306
PostgreSQL5432

πŸš€ Wrap-Up: You’re a Security Pro Now! πŸ’ͺ

Awesome job, coder fam! πŸŽ‰ You’ve just learned:

  • πŸ” What security groups are
  • πŸšͺ How to control access to your EC2
  • βœ… Best practices for safety

Now your EC2 is like a fortressβ€”strong & secure! 🏰


πŸ‘‰ Next up: We’ll dive into deploying a real-world app with perfect security settings.

πŸŽ₯ Stay tuned & subscribe:

Share the Post:
Picture of Web Codder

Web Codder

Vikas Sankhla is a seasoned Full Stack Developer with over 7 years of experience in web development. He is the founder of Web Codder, a platform dedicated to providing comprehensive web development tutorials and resources. Vikas specializes in the MERN stack (MongoDB, Express.js, React.js, Node.js) and has been instrumental in mentoring aspiring developers through his online courses and content. His commitment to simplifying complex web technologies has made him a respected figure in the developer community.

Related Posts