System Administration – Linux Teaching Plan

Duration: 2 hours (≈ 12 min per command). Audience: Users who want to learn the core tools for everyday system management on a Linux machine.

Learning Objectives

  1. Inspect and modify system identity, time, and hardware information.
  2. Manage users, groups, and passwords securely.
  3. Control system services with systemd.
  4. Monitor system resources and swap usage.
  5. Configure storage (filesystems, mount points, partitions).
  6. Set up basic logging and view system logs.
  7. Configure and test firewall rules with iptables/nftables.
  8. Schedule recurring tasks with cron.
  9. Create, run, and clean up systemd timers.
  10. Perform routine maintenance: updates, cleanups, backups, and restores.

Schedule & Topics

  1. Introduction & terminology (5 min)
  2. uname & hostnamectl (10 min)
  3. timedatectl & hwclock (10 min)
  4. useradd, usermod, passwd (10 min)
  5. groupadd & gpasswd (10 min)
  6. systemctl start/stop/status (10 min)
  7. journalctl & dmesg (10 min)
  8. df & du (10 min)
  9. free & top (10 min)
  10. iptables/nftables (10 min)
  11. cron & crontab (10 min)
  12. systemd timer (10 min)
  13. apt/dpkg or yum update (10 min)
  14. Backup & restore with tar/rsync (15 min)
  15. Q&A & wrap‑up (5 min)

Command Topics & Hands‑On Exercises

1. uname -a – System Identification

uname -a

2. hostnamectl – Set Hostname and System Info

sudo hostnamectl set-hostname mylinuxbox
hostnamectl

3. timedatectl – View & Set System Time

timedatectl
sudo timedatectl set-time "2024-06-10 12:00:00"

4. hwclock – Sync RTC

sudo hwclock --systohc
hwclock --show

5. useradd – Create a New User

sudo useradd -m -s /bin/bash newuser
sudo passwd newuser
id newuser

6. usermod – Modify a User

sudo usermod -aG sudo newuser
sudo groups newuser

7. passwd – Change User Password

sudo passwd newuser

8. groupadd – Create a Group

sudo groupadd developers
sudo usermod -aG developers newuser
groups newuser

9. systemctl – Service Control

sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh
sudo systemctl restart ssh

10. journalctl – View System Logs

journalctl -xe
journalctl --since "2024-06-01" --unit ssh

11. dmesg – Kernel Messages

dmesg | tail
dmesg | grep -i usb

12. df – Disk Space Usage

df -h /
df -hT /var

13. du – Directory Size

du -sh /var
du -h --max-depth=1 /

14. free – Memory Usage

free -h
free -m | grep Mem

15. top – Real‑time Process Monitoring

top -b -n 1 | head
top -c

16. iptables – Basic Firewall

sudo iptables -F
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -j DROP
sudo iptables-save

17. nft – Modern Firewall

sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }
sudo nft add rule inet filter input tcp dport 22 accept
sudo nft list ruleset

18. crontab – Schedule Tasks

crontab -l
(crontab -l 2>/dev/null; echo "0 2 * * * /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y") | crontab -
crontab -l

19. systemd-timer – Trigger Jobs Automatically

sudo tee /etc/systemd/system/backup.service gt; /dev/null <<'EOF'
[Unit]
Description=Daily backup

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
EOF
sudo tee /etc/systemd/system/backup.timer > /dev/null <<'EOF'
[Unit]
Description=Runs backup.service daily

[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true

[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable backup.timer
sudo systemctl start backup.timer
sudo systemctl list-timers | grep backup
EOF

20. tar – Archive and Compress Files

tar -czf ~/myhome.tgz ~/
tar -xzf ~/myhome.tgz -C ~/restore
ls ~/restore

Mini‑Project: “Full Server Setup Script”

Students will combine the 10+ commands into a single bash script that:

  1. Detects the Linux distribution.
  2. Updates the system (apt/yum/dnf/pacman/etc.).
  3. Installs nginx, postgresql, and git.
  4. Creates a system user deploy with SSH access.
  5. Sets up a firewall rule to allow HTTP, HTTPS, and SSH.
  6. Creates a systemd timer that backs up the website directory every night.
  7. Logs all actions to `/var/log/server-setup.log`.
  8. Ensures idempotence: re‑running the script detects already‑installed components and skips them.

Students will run the script on a fresh VM, capture the log file, and demonstrate the website and backup timer in action.

Assessment

  1. Quiz (5 min): 5 multiple‑choice questions covering key system‑admin commands.
  2. Hands‑on check (10 min): each student performs 3 operations (add user, enable service, set firewall) and demonstrates the outcome.
  3. Project review (10 min): the instructor walks through each script file, asking the student to explain why each command was used.

Resources

All commands are available on most Linux distributions and can be run as normal users or with sudo where necessary. Practice in a safe lab environment is essential before touching production systems.