4. Amazon EC2: Launch and Connect to Your Linux Server
4.6 First Commands After Login and Instance Metadata
Login zala ki pahile kahi commands – OS confirm kara, updates ghya, time zone set kara.
cat /etc/os-release # confirm distribution
sudo yum update -y # AL2023 / CentOS Stream
sudo apt update && sudo apt upgrade -y # Ubuntu
curl -s http://169.254.169.254/latest/meta-data/ -H "X-aws-ec2-metadata-token: $(curl -s -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60')"
sudo timedatectl set-timezone Asia/Kolkata
Instance metadata (IMDSv2)
169.254.169.254 is a special address inside every instance that returns its metadata — instance ID, public IP, AZ, IAM role credentials. New instances require IMDSv2 (token-based), which is why the command above first requests a token. Example: append public-ipv4 or placement/availability-zone to the URL.
Why this matters for security
The metadata service at 169.254.169.254 can return temporary IAM role credentials. In an SSRF attack (Part 11), a vulnerable web app is tricked into fetching this URL for the attacker. IMDSv2 (session tokens) makes this much harder – keep it set to required on every instance.
Ravindra Bagale's Tip
Many students copy the old IMDSv1 curl command from the internet and get confused when they see "401". New instances need a token – use the IMDSv2 command above. And never make IMDSv2 "optional" – it's there for security.
Ravindra Bagale's Tip – मराठी
बरेच students IMDSv1 वाला जुना curl command internet वरून copy करतात आणि "401" आलं की गोंधळतात. नवीन instances वर token लागतो – वरचा IMDSv2 command वापरा. आणि IMDSv2 ला कधी "optional" करू नका, ते security साठी आहे.
Ravindra Bagale's Tip – हिंदी
बहुत से students IMDSv1 वाला पुराना curl command internet से copy करते हैं और "401" आने पर उलझ जाते हैं. नए instances पर token चाहिए – ऊपर वाला IMDSv2 command इस्तेमाल करो. और IMDSv2 को कभी "optional" मत करना, वह security के लिए है.
Practice task
Using IMDSv2, print your instance ID, public IPv4 and availability zone (append instance-id, public-ipv4 and placement/availability-zone).
Extended teaching notes
Why this lesson matters
A SOC turns logs into action. Good juniors triage with playbooks: what fired, which asset, how bad, contain or escalate, write the timeline.
- Prepare: asset list, contacts, runbooks.
- Detect: SIEM/EDR alerts with context.
- Contain: disable account, isolate host, block IOC.
- Eradicate & recover: patch, rebuild, restore.
- Lessons: one improvement ticket per incident.
Indian company (sample)
A 24×7 SOC at a large Indian IT services firm handles phishing and malware for many clients. Tier-1 analysts follow a script; they do not freestyle on production.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.