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 Rules | Who can connect to your EC2 (like visitors at your door πͺ) |
Outbound Rules | Where your EC2 can send data (like you making calls π) |
Example:
Rule Type | Port | Protocol | Source | What It Does |
---|---|---|---|---|
Inbound | 22 | TCP | Your IP only | Allows only you to SSH into EC2 |
Inbound | 80 | TCP | Anywhere (0.0.0.0/0) | Allows anyone to visit your website |
Outbound | All | All | Anywhere | Allows EC2 to reach the internet |
π οΈ Setting Security Group Rules (Step-by-Step)
1οΈβ£ Go to EC2 Dashboard
- Open AWS Console
- Click EC2 > Security Groups
2οΈβ£ Create a New Security Group
- Name: MyWebServerSG
- Description: Security for my web server
- VPC: Choose default (or your VPC)
3οΈβ£ Add Inbound Rules β‘οΈ
Type | Protocol | Port Range | Source | Reason |
---|---|---|---|---|
SSH | TCP | 22 | My IP | So only you can log in |
HTTP | TCP | 80 | 0.0.0.0/0 | Allow everyone to visit your site |
HTTPS | TCP | 443 | 0.0.0.0/0 | Allow 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.

1οΈβ£ EC2 Instance π₯οΈ
2οΈβ£ Security Group π
3οΈβ£ Inbound/Outbound Rules β‘οΈβ¬
οΈ
4οΈβ£ Safe & Secure Hosting! π
β Bonus: Common Ports Cheat Sheet
Service | Port Number |
---|---|
SSH | 22 |
HTTP | 80 |
HTTPS | 443 |
MySQL | 3306 |
PostgreSQL | 5432 |
π 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: