Why Linux for AWS?

Over 90% of cloud workloads run on Linux. EC2 instances, ECS containers, Lambda environments — all Linux. Understanding Linux means you can:

  • Debug EC2 instances via SSH
  • Write UserData bootstrap scripts
  • Create and manage Docker containers
  • Answer scenario questions on SOA-C02 & DVA-C02 exams
💡 Tip

On EC2: /var/log/cloud-init.log contains your UserData script output — critical for debugging bootstrap issues.

Linux File System

DirectoryPurpose
/Root of the entire filesystem
/binEssential user binaries (ls, cp, mv)
/etcConfiguration files
/homeUser home directories
/varVariable data (logs, databases, mail)
/tmpTemporary files (cleared on reboot)
/procVirtual filesystem for kernel/process info
/optOptional software packages

File Permissions

-rwxr-xr-- 1 ubuntu aws-team 1234 Jul 10 12:00 deploy.sh
 │└──┬──┘└──┬──┘└──┬──┘
 │   │      │      └── Other: r-- (4)
 │   │      └───────── Group: r-x (5)
 │   └──────────────── Owner: rwx (7)
PermissionSymbolOctal
Readr4
Writew2
Executex1
None-0
chmod 755 script.sh        # rwxr-xr-x
chmod +x script.sh         # Add execute for all
chown ubuntu:team file.txt # Change owner:group
⚠ AWS Exam Tip

SSH key pairs must have chmod 400 permissions. AWS refuses connection if the .pem file is too permissive.

Essential Commands

# Navigation
pwd; ls -la; cd /var/log; cd ~; cd -

# Files
cp source dest; mv file newname; rm -rf dir/
mkdir -p a/b/c; touch file.txt
cat file.txt; less file.txt; tail -f /var/log/syslog

# Search
find / -name "*.log" -type f
grep -r "ERROR" /var/log/
grep -i "warning" app.log
which python3; whereis nginx

# Archives
tar -czvf archive.tar.gz /mydir
tar -xzvf archive.tar.gz
zip -r backup.zip /mydir; unzip backup.zip

Processes & System Info

ps aux                  # All running processes
ps aux | grep nginx     # Filter for nginx
top                     # Real-time process viewer
kill PID                # Graceful stop (SIGTERM)
kill -9 PID             # Force kill (SIGKILL)
free -h                 # Memory usage
df -h                   # Disk usage
uname -a                # Kernel info
uptime                  # System uptime and load

Linux Networking Commands

ip addr show                  # Show IP addresses
ping -c 4 8.8.8.8             # ICMP ping
traceroute google.com         # Trace route to host
nslookup example.com          # DNS lookup
dig example.com               # Detailed DNS query
netstat -tulnp                # All listening ports
ss -tulnp                     # Modern netstat
curl -I https://example.com   # HTTP headers
curl -v https://api.example.com  # Verbose HTTP
⚠ AWS Exam Tip

If you can ping an EC2 but can't connect on port 22, check the Security Group inbound rules — AWS Security Groups are applied before traffic reaches the OS firewall.

Shell Scripting

#!/bin/bash
# EC2 UserData example
REGION="us-east-1"
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)

if [ -f "/etc/nginx/nginx.conf" ]; then
  echo "Nginx config exists"
fi

for FILE in /var/log/*.log; do
  echo "Processing: $FILE"
done

# Error handling
set -e          # Exit on first error
set -u          # Treat unset vars as error

# UserData script pattern
yum update -y
yum install -y nginx
systemctl start nginx
systemctl enable nginx

SSH & EC2 Access

# Connect to EC2
chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@54.123.45.67   # Amazon Linux
ssh -i my-key.pem ubuntu@54.123.45.67     # Ubuntu

# SSH config (~/.ssh/config)
Host my-ec2
    HostName 54.123.45.67
    User ec2-user
    IdentityFile ~/.ssh/my-key.pem
# Then just: ssh my-ec2

# SCP — copy files
scp -i key.pem file.txt ec2-user@IP:/home/ec2-user/

# Port forwarding (tunnel to private RDS)
ssh -i key.pem -L 5432:rds-endpoint:5432 ec2-user@IP
💡 EC2 Instance Connect

Provides browser-based SSH access without key pairs — uses IAM permissions instead. Great for exam questions about "SSH access without managing key pairs".

Systemd & Services

systemctl start nginx     # Start service
systemctl stop nginx      # Stop service
systemctl restart nginx   # Restart
systemctl enable nginx    # Auto-start on boot
systemctl status nginx    # Current status
journalctl -u nginx -f    # Follow service logs
journalctl -xe            # Recent errors

📋 Study Checklist

Progress0%
  • Understand the Linux directory structure
  • Know how file permissions work (rwx / octal)
  • Use chmod, chown commands
  • Navigate with cd, ls, pwd, find
  • Edit files with nano or vim
  • Manage processes with ps, top, kill
  • Use grep, awk, sed for text processing
  • Write a basic bash script with variables and loops
  • Install packages with yum/apt
  • Manage services with systemctl
  • Connect to EC2 via SSH with key pair
  • Set and use environment variables
  • Schedule tasks with cron
  • Use networking commands (ping, netstat, curl, dig)
  • View and tail logs with tail -f and journalctl
  • Use pipes and redirects (|, >, >>, 2>&1)
  • Understand EC2 UserData scripts
  • Know where AWS credential files are stored (~/.aws/)
  • Understand IMDS (Instance Metadata Service at 169.254.169.254)
  • Know the difference between yum (Amazon Linux) and apt (Ubuntu)