⚙️ System Administration

Learn essential system administration and monitoring techniques

💻 Practice While You Learn!

Click the green 💻 Terminal button in the bottom-right corner to open an interactive terminal. You can practice all the commands on this page in real-time!

  • The terminal stays open as you navigate between pages
  • Try commands immediately after reading about them
  • Use ↑/↓ arrows for command history, Tab for auto-complete

Process Management

Understanding and managing processes is crucial for system administration. Every running program is a process.

Viewing Processes

Common Process Commands

Key commands: ps📊 ps - Process StatusDisplays information about running processes. Essential for system monitoring and troubleshooting.List All Processes$ ps aux▸ Shows all processes with detailed informationCurrent User Processes$ ps ux▸ Shows processes for current user onlyFind Specific Process$ ps aux | grep firefox▸ Searches for processes containing 'firefox' top📈 top - Task ManagerInteractive real-time process viewer showing CPU, memory usage, and system statistics.Launch top$ top▸ Opens interactive process monitorSort by CPU$ Press 'P' in top▸ Sorts processes by CPU usageSort by Memory$ Press 'M' in top▸ Sorts processes by memory usage

# List all running processes
ps aux

# Show processes in a tree structure
pstree

# Interactive process viewer
top

# Modern alternative to top
htop

# List processes for current user
ps ux

# Find specific process
ps aux | grep firefox

Process Information

Understanding ps aux Output

  • USER: Process owner
  • PID: Process ID (unique identifier)
  • %CPU: CPU usage percentage
  • %MEM: Memory usage percentage
  • VSZ: Virtual memory size
  • RSS: Physical memory (RAM) used
  • STAT: Process state (R=running, S=sleeping, Z=zombie)
  • COMMAND: Command that started the process

Managing Processes

Controlling Processes

Key commands: kill🛑 kill - Terminate ProcessSends signals to processes, typically to terminate them. Use PID (Process ID) to target specific process.Graceful Termination$ kill 1234▸ Sends SIGTERM (allows cleanup)Force Kill$ kill -9 1234▸ Sends SIGKILL (immediate termination)Kill by Name$ killall firefox▸ Kills all processes named 'firefox' bg⏯️ bg - Background ProcessResumes a suspended job in the background, allowing you to continue using the terminal.Resume Latest Job$ bg▸ Continues most recent suspended job in backgroundResume Specific Job$ bg %2▸ Resumes job number 2 in background fg▶️ fg - Foreground ProcessBrings a background job to the foreground, giving it control of the terminal.Bring Latest Job Forward$ fg▸ Brings most recent background job to foregroundBring Specific Job$ fg %1▸ Brings job number 1 to foreground jobs📋 jobs - List Background JobsLists jobs running in the background or suspended in the current shell session.List All Jobs$ jobs▸ Shows all background and suspended jobsList with PIDs$ jobs -l▸ Shows jobs with their process IDs

# Kill process by PID
kill 1234

# Force kill a process
kill -9 1234

# Kill process by name
killall firefox

# Send SIGTERM signal
kill -15 1234

# Background a running process
Ctrl+Z        # Suspend
bg            # Continue in background

# Foreground a background process
fg

# Run command in background from start
command &

⚠️ Using kill Carefully

kill -9 forcefully terminates a process without cleanup. Use regular kill first to allow graceful shutdown.

System Monitoring

System Resources

Monitoring Commands

# CPU and memory usage (interactive)
top

# Disk usage by filesystem
df -h

# Disk usage by directory
du -sh /home/user/*

# Memory usage
free -h

# System uptime and load average
uptime

# Who is logged in
who

# Detailed who information
w

Understanding System Load

Load Average Explained

When you run uptime, you see something like:

11:30:45 up 5 days, 3:42, 2 users, load average: 0.15, 0.25, 0.30

The three numbers represent average system load over 1, 5, and 15 minutes:

  • < 1.0: System has spare capacity
  • = Number of CPUs: Fully utilized
  • > Number of CPUs: Processes are waiting

Log Files

Viewing System Logs

# View system log
sudo tail -f /var/log/syslog

# View authentication log
sudo tail -f /var/log/auth.log

# View kernel messages
dmesg | tail

# View systemd journal
journalctl -xe

# Follow journal in real-time
journalctl -f

Package Management

Different Linux distributions use different package managers. Here are the most common ones:

Debian/Ubuntu (apt)

APT Package Manager

# Update package list
sudo apt update

# Upgrade all packages
sudo apt upgrade

# Install a package
sudo apt install package-name

# Remove a package
sudo apt remove package-name

# Search for package
apt search keyword

# Show package information
apt show package-name

Red Hat/CentOS/Rocky (yum/dnf)

YUM/DNF Package Manager

# Install package
sudo yum install package-name
sudo dnf install package-name

# Update all packages
sudo yum update
sudo dnf upgrade

# Remove package
sudo yum remove package-name

# Search for package
yum search keyword

# List installed packages
yum list installed

Arch Linux (pacman)

Pacman Package Manager

# Update package database and upgrade
sudo pacman -Syu

# Install package
sudo pacman -S package-name

# Remove package
sudo pacman -R package-name

# Search for package
pacman -Ss keyword

# List installed packages
pacman -Q

Service Management (systemd)

Modern Linux distributions use systemd to manage services (daemons).

Managing Services

# Start a service
sudo systemctl start nginx

# Stop a service
sudo systemctl stop nginx

# Restart a service
sudo systemctl restart nginx

# Check service status
sudo systemctl status nginx

# Enable service at boot
sudo systemctl enable nginx

# Disable service at boot
sudo systemctl disable nginx

# List all services
systemctl list-units --type=service

# List failed services
systemctl --failed

Service States

  • active (running): Service is running
  • active (exited): Service completed successfully
  • inactive (dead): Service is stopped
  • failed: Service crashed or failed to start

Networking Basics

Network Information

Network Commands

# Show IP addresses
ip addr show
ip a

# Show network interfaces (old method)
ifconfig

# Show routing table
ip route show

# Test connectivity
ping google.com

# Trace route to destination
traceroute google.com

# DNS lookup
nslookup google.com
dig google.com

# Show listening ports
sudo netstat -tuln
sudo ss -tuln

Firewall Management

UFW (Uncomplicated Firewall)

# Enable firewall
sudo ufw enable

# Disable firewall
sudo ufw disable

# Allow port
sudo ufw allow 80/tcp
sudo ufw allow ssh

# Deny port
sudo ufw deny 23

# Show status
sudo ufw status

# Show numbered rules
sudo ufw status numbered

# Delete rule by number
sudo ufw delete 2

Practical Scenarios

Scenario 1: High CPU Usage

# 1. Check what's using CPU
top
# Press 'P' to sort by CPU usage

# 2. Identify the problematic process
# Look at PID of high CPU process

# 3. Investigate the process
ps aux | grep [PID]

# 4. If needed, kill the process
kill [PID]

Scenario 2: Disk Space Full

# 1. Check disk usage
df -h

# 2. Find large directories
du -sh /home/* | sort -h

# 3. Find large files
find /home -type f -size +100M -exec ls -lh {} \;

# 4. Clean up package cache (Ubuntu/Debian)
sudo apt clean
sudo apt autoremove

Scenario 3: Service Won't Start

# 1. Check service status
sudo systemctl status servicename

# 2. View recent logs
sudo journalctl -u servicename -n 50

# 3. Check configuration
sudo systemctl cat servicename

# 4. Restart service
sudo systemctl restart servicename

Key Takeaways

  • Use top or htop for real-time system monitoring
  • Understand process states and how to manage them
  • Regularly check disk space and system logs
  • Know your distribution's package manager
  • systemctl is the standard for service management
  • Monitor network connections and firewall rules
  • Practice troubleshooting in a safe environment first

Practice Tips

Ready to practice? Head over to the Interactive Terminal to try system administration commands!

EN
AR
EN
AR