How I Secured My First EC2 Instance (And Didn’t Get Hacked) AWS for Beginners – Part 3

Okay, real talk—when I launched my first EC2 instance, I was hyped. That feeling of spinning up your own server on the cloud? Felt like I had unlocked a new level. 😎

But then came the what now? moment.

I saw all these terms: key pair, security group, SSH, port 22... and my excitement turned into confusion real quick.

So if you're just starting out like I was, this blog is for you. I'm going to walk you through how I set up my EC2 instance securely, without frying my brain. No boring lectures. Just real stuff from my own experience.


🛡️ Why Security Matters (Even for Beginners)

When you're playing around on AWS, it's easy to ignore security because you're just "learning". But trust me—even a simple mistake like opening your EC2 to everyone can attract bots, brute-force attacks, or worse.

I learned this early. And it was a wake-up call. So here’s how I made sure my EC2 was safe (and how you can too).


🔑 Step 1: Creating a Key Pair – My EC2’s House Key

This part felt cool and a bit spy-movie-like.

  • I went to the EC2 Dashboard > Key Pairs

  • Clicked Create Key Pair

  • Gave it a cool name like aws-master-key (felt like a hacker already 😅)

  • And BAM! It downloaded a .pem file

👉 Pro tip from me: Save that file in a safe place. AWS doesn’t give it to you again. I repeat—**DO NOT LOSE IT.
(It’s like losing the only key to your house.)


🔐 Step 2: Setting Up Security Groups – My EC2’s Bodyguards

I used to think: “Why all this firewall stuff? I just wanna deploy stuff.”
Then I understood—Security Groups are the gatekeepers. They decide who can talk to your instance and through which ports.

Here's what I did:

  • While launching the instance, I created a new security group

  • For inbound rules, I added:

    • Type: SSH

    • Port: 22

    • Source: My IP only (Trust me, don’t use "Anywhere" unless you like living dangerously 😅)

That way, only my system could access the EC2 via SSH. It felt powerful and safe.


💻 Step 3: The First Connection – SSH-ing Like a Pro (Or at Least Trying 😅)

Now came the moment of truth. Connecting to my EC2 using that .pem file.

I opened my terminal and typed:

bashCopyEditchmod 400 aws-master-key.pem
ssh -i "aws-master-key.pem" ec2-user@your-ec2-public-ip

Hit enter... and boom, I was inside my cloud server.
No GUI. Just a blinking cursor. But man, I felt like Tony Stark for a moment.


🧠 Lessons I Learned (The Hard-ish Way)

  • Your .pem file is everything – don’t delete it thinking it's just a random file.

  • Avoid 0.0.0.0/0 in Security Groups unless you're just testing something quick.

  • Use a fixed IP (Elastic IP) if you’re going to need to access it often.

  • Always shut down or terminate EC2s you don’t need—AWS can get expensive real quick 💸


✨ From Confusion to Confidence

When I first saw EC2 and all its settings, I felt overwhelmed. But the more I played with it, the more it started to make sense.

So if you're reading this and thinking,

“Bro, this is too much,”
I promise—it gets easier.

Just take it step by step. One config at a time.


🏁 What's Next?

Now that we’ve set up a secure EC2 instance, it’s time to make it do something.
Next up, I’m going to show how I installed a web server (Apache/Nginx) and hosted my first site from EC2. It’s gonna be 🔥

Thanks for reading. If you found this helpful, let’s connect! Or just drop a comment—always happy to help a fellow cloud warrior 💪

0
Subscribe to my newsletter

Read articles from Tarvin Kumar Thakur directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tarvin Kumar Thakur
Tarvin Kumar Thakur

Passionate about exploring the intersection of cloud, AI, and robotics! 🚀 I love building smart systems, experimenting with AWS, and bringing machines to life with machine learning. Always learning, always creating—one project at a time!