2. Ports and Protocols: SSH, HTTP, HTTPS, FTP/SFTP and DNS
2.2 SSH (Secure Shell) – Port 22
SSH ha aapla roj cha tool aahe – EC2 la login, files copy (scp/sftp), remote commands. Te encrypted aahe, pan chukiche configuration kela tar attackers sathi pahila target pan tech.
How key-based login works (simple view):
Your laptop Server (EC2)
private key mykey.pem (never leaves) ~/.ssh/authorized_keys (public key)
| 1. TCP connect to port 22 |
| 2. Server proves its identity (host key) ---->| you accept fingerprint once
| 3. Encrypted channel agreed (key exchange) |
| 4. Server sends a challenge |
| 5. Laptop signs it with the PRIVATE key ----->| verified with PUBLIC key
| 6. Login allowed, shell opened |
ssh -i mykey.pem ec2-user@<PUBLIC_IP> # Amazon Linux
ssh -i mykey.pem ubuntu@<PUBLIC_IP> # Ubuntu
ssh-keygen -t ed25519 -C "raja@lab" # create your own key pair
cat ~/.ssh/known_hosts # servers you have trusted before
Why this matters for security
Internet-facing SSH receives automated password-guessing (brute force) attempts all the time. Key-based authentication (ओळख पडताळणी), disabling password and root login, limiting port 22 to your own IP and tools like fail2ban (Part 11) are the standard defences. A leaked private key is as bad as a leaked password – anyone holding it can log in.
Ravindra Bagale's Tip
When "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED" appears, many students immediately delete known_hosts. Wait! If you've just launched a new EC2 instance this is normal, but otherwise it can be a sign of a man-in-the-middle attack. First understand the reason, then remove only that one line: ssh-keygen -R <IP>.
Ravindra Bagale's Tip – मराठी
"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED" दिसलं की बरेच students लगेच known_hosts delete करतात. थांबा! EC2 नवीन launch केला असेल तर हे normal आहे, पण नाहीतर हे man-in-the-middle चं लक्षण असू शकतं. आधी कारण समजून घ्या, मग फक्त ती एक line काढा: ssh-keygen -R <IP>.
Ravindra Bagale's Tip – हिंदी
"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED" दिखते ही बहुत से students तुरंत known_hosts delete कर देते हैं. रुको! अगर नया EC2 launch किया है तो यह normal है, वरना यह man-in-the-middle का संकेत हो सकता है. पहले वजह समझो, फिर सिर्फ़ वह एक line हटाओ: ssh-keygen -R <IP>.
Practice task
Generate an ED25519 key pair with ssh-keygen, look at both files in ~/.ssh/, and explain which file you may share and which you must never share.
Extended teaching notes
Why this lesson matters
Hardening is deleting unnecessary risk: fewer packages, fewer open ports, fewer privileged accounts, faster patches, better logs.
Hardening related services
[('SSH', 'Key auth, no root login, Fail2ban or equivalent, SG limited to your IP/VPN.', '', ''), ('SMB / NFS / LDAP / SNMP', 'Do not expose to the internet; patch; strong auth; disable unused versions (e.g. SMBv1).', '', ''), ('SMTP', 'Authenticated relay only; SPF/DKIM/DMARC for your domains.', '', ''), ('DNS', 'Restrict zone transfers; monitor for unexpected records (crt.sh for certs).', '', ''), ('Firewalls', 'Host firewall + cloud SG/NSG; default deny; document every allow.', '', '')]
Real examples
Global: CIS Benchmarks exist for Linux, Windows and clouds. Indian company (sample): a Pune team requires SSH keys only and weekly patch windows for internet-facing hosts.
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.