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
- Inspect and modify system identity, time, and hardware information.
- Manage users, groups, and passwords securely.
- Control system services with systemd.
- Monitor system resources and swap usage.
- Configure storage (filesystems, mount points, partitions).
- Set up basic logging and view system logs.
- Configure and test firewall rules with iptables/nftables.
- Schedule recurring tasks with cron.
- Create, run, and clean up systemd timers.
- Perform routine maintenance: updates, cleanups, backups, and restores.
Schedule & Topics
- Introduction & terminology (5 min)
- uname & hostnamectl (10 min)
- timedatectl & hwclock (10 min)
- useradd, usermod, passwd (10 min)
- groupadd & gpasswd (10 min)
- systemctl start/stop/status (10 min)
- journalctl & dmesg (10 min)
- df & du (10 min)
- free & top (10 min)
- iptables/nftables (10 min)
- cron & crontab (10 min)
- systemd timer (10 min)
- apt/dpkg or yum update (10 min)
- Backup & restore with tar/rsync (15 min)
- Q&A & wrap‑up (5 min)
Command Topics & Hands‑On Exercises
1. uname -a – System Identification
uname -a
- Run `uname -a` on a Linux VM and identify the kernel version, machine hardware, and operating system name.
- Compare output on Debian vs. Arch systems.
2. hostnamectl – Set Hostname and System Info
sudo hostnamectl set-hostname mylinuxbox
hostnamectl
- Change the hostname to “mylinuxbox” and verify the new name with `hostnamectl`.
- Check that the change persists after reboot.
3. timedatectl – View & Set System Time
timedatectl
sudo timedatectl set-time "2024-06-10 12:00:00"
- Display the current system clock and timezone.
- Set a new system time and confirm the change with `date`.
4. hwclock – Sync RTC
sudo hwclock --systohc
hwclock --show
- Write the system clock to the hardware clock (RTC) with `hwclock --systohc`.
- Read back the RTC time with `hwclock --show` and compare it to `date`.
5. useradd – Create a New User
sudo useradd -m -s /bin/bash newuser
sudo passwd newuser
id newuser
- Create a user called
newuser with a home directory.
- Set a password and log in as
newuser using `su - newuser`.
- Verify group membership with `id newuser`.
6. usermod – Modify a User
sudo usermod -aG sudo newuser
sudo groups newuser
- Add
newuser to the sudo group.
- Confirm the new group membership with `groups newuser`.
- Test sudo access by running `sudo whoami` as
newuser.
7. passwd – Change User Password
sudo passwd newuser
- Change the password for
newuser and verify that the old password fails.
- Use `sudo passwd -S newuser` to show the password aging status.
8. groupadd – Create a Group
sudo groupadd developers
sudo usermod -aG developers newuser
groups newuser
- Create a group called
developers.
- Add
newuser to the group.
- Show the group membership with `groups newuser`.
9. systemctl – Service Control
sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh
sudo systemctl restart ssh
- Check the status of the SSH service and start it if it’s not running.
- Enable the service to start on boot.
- Restart the service and view the journal with `journalctl -u ssh`.
10. journalctl – View System Logs
journalctl -xe
journalctl --since "2024-06-01" --unit ssh
- View the most recent system logs with `journalctl -xe`.
- Filter logs from a specific time range for the SSH unit.
11. dmesg – Kernel Messages
dmesg | tail
dmesg | grep -i usb
- Show the last ten kernel messages.
- Search for USB device related messages with a case‑insensitive grep.
12. df – Disk Space Usage
df -h /
df -hT /var
- Display filesystem usage for root and the /var directory in human readable form.
- Show the filesystem type for /var.
13. du – Directory Size
du -sh /var
du -h --max-depth=1 /
- Show the total size of /var in a single number.
- List the sizes of the top‑level directories on root.
14. free – Memory Usage
free -h
free -m | grep Mem
- View memory usage in human readable format.
- Extract the line containing “Mem” and show only the used memory column.
15. top – Real‑time Process Monitoring
top -b -n 1 | head
top -c
- Run top in batch mode to capture a single snapshot into the console.
- Start top in interactive mode and press
c to toggle the command line column.
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
- Flush all existing rules.
- Allow SSH traffic on port 22.
- Drop all other incoming packets.
- Save the rules to `/etc/iptables/rules.v4` and ensure they load at boot with `iptables-restore`.
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
- Set up a basic filter table, create an input chain, and drop everything by default.
- Add a rule to allow SSH traffic.
- Print the active 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
- View the current user’s crontab.
- Append a nightly system update job that runs at 2 AM.
- Verify the new entry appears in the crontab.
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
- Create a simple `backup.sh` script that echoes “Backup ran” into `/var/log/backup.log`.
- Set up a systemd timer to run that script at 3 AM every day.
- Show that the timer is enabled and active with `systemctl list-timers`.
20. tar – Archive and Compress Files
tar -czf ~/myhome.tgz ~/
tar -xzf ~/myhome.tgz -C ~/restore
ls ~/restore
- Archive the home directory into a compressed tarball.
- Extract the archive into a separate directory and verify the file list.
Mini‑Project: “Full Server Setup Script”
Students will combine the 10+ commands into a single bash script that:
- Detects the Linux distribution.
- Updates the system (apt/yum/dnf/pacman/etc.).
- Installs
nginx, postgresql, and git.
- Creates a system user
deploy with SSH access.
- Sets up a firewall rule to allow HTTP, HTTPS, and SSH.
- Creates a systemd timer that backs up the website directory every night.
- Logs all actions to `/var/log/server-setup.log`.
- 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
- Quiz (5 min): 5 multiple‑choice questions covering key system‑admin commands.
- Hands‑on check (10 min): each student performs 3 operations (add user, enable service, set firewall) and demonstrates the outcome.
- 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.