45. Practice Exercises with Hints
45.3 Linux on EC2 – Commands You Must Type Blind
Amazon Linux habit: sudo yum install, sudo service <name> start|stop|restart|status. Permissions, users, logs, processes – Blue daily bread.
| Exercise | Task | Hint |
|---|---|---|
| E1 | Install and start Nginx on Amazon Linux; prove status | sudo yum install nginx -y then sudo service nginx start and sudo service nginx status |
| E2 | Create user amir, add to wheel carefully, set chmod 400 on SSH key on client |
Never chmod 777 keys; ssh -i key.pem ec2-user@... from your PC |
| E3 | Find failed SSH logins in logs (path may vary) | /var/log/secure on Amazon Linux; sudo grep -i failed /var/log/secure \| tail |
| E4 | Explain why chmod 777 /var/www/html is a student favourite mistake |
World-writable web root = defacement / webshell drop easy |
| E5 | Write a one-line cron that runs a backup script at 02:00 (lab) | 0 2 * * * /home/ec2-user/backup.sh – test script path first |
| E6 | ss -tulnp or netstat – list listening ports; mark unexpected |
Blue baseline: know what should listen |
| Red team (attacker) does | Blue team (defender) detects / stops |
|---|---|
| Brutes SSH on open port 22 from internet | Key-only SSH; fail2ban; SG allow your IP; no password auth |
| Looks for world-writable web dirs after foothold | Correct ownership; no 777; file integrity / package verify |
Ravindra Bagale's Tip
Students systemctl start lihun Amazon Linux notes madhe confuse hotat. Hya book madhe service control = sudo service. Boot enable = sudo systemctl enable OK. Dhyan rakho.
Lab
On OWN Free Tier Amazon Linux: install httpd, sudo service httpd start, open SG 80 from your IP, browse Elastic IP. Then sudo service httpd stop and confirm site down. Notes: 6 command lines + screenshot.