Hands-on Lab

#Lab 02: System Administration

Practice essential Linux system administration tasks.

#🎯 Objectives

  • Create and manage users
  • Configure services
  • Monitor system health

#Task 1: User Management

bash
1# Create a new user
2sudo useradd -m -s /bin/bash developer
3sudo passwd developer
4
5# Add to sudo group
6sudo usermod -aG sudo developer
7
8# Create a group
9sudo groupadd devops
10
11# Add user to group
12sudo usermod -aG devops developer
13
14# Verify
15groups developer

#Task 2: Service Management

bash
1# Create a simple web service
2sudo mkdir -p /var/www/html
3echo "<h1>Hello DevOps!</h1>" | sudo tee /var/www/html/index.html
4
5# Install nginx
6sudo apt install -y nginx
7
8# Enable and start
9sudo systemctl enable nginx
10sudo systemctl start nginx
11
12# Check status
13sudo systemctl status nginx
14
15# View in browser or curl
16curl localhost

#Task 3: System Monitoring

bash
1# Create monitoring script
2cat << 'EOF' > ~/monitor.sh
3#!/bin/bash
4echo "=== System Health Report ==="
5echo "Date: $(date)"
6echo ""
7echo "=== CPU Load ==="
8uptime
9echo ""
10echo "=== Memory Usage ==="
11free -h
12echo ""
13echo "=== Disk Usage ==="
14df -h /
15echo ""
16echo "=== Top Processes ==="
17ps aux --sort=-%cpu | head -6
18EOF
19
20chmod +x ~/monitor.sh
21
22# Run it
23./monitor.sh

#Task 4: Log Analysis

bash
1# Find errors in syslog
2sudo grep -i error /var/log/syslog | tail -20
3
4# Count error types
5sudo grep -i error /var/log/syslog | awk '{print $5}' | sort | uniq -c | sort -rn

#✅ Success Criteria

  • User 'developer' exists with sudo access
  • Nginx is running and accessible
  • Monitor script works
  • Can analyze log files

#🎓 What You Learned

  • User and group management
  • Service lifecycle management
  • Basic monitoring scripts
  • Log analysis with grep/awk