Part 3: Permissions & Processes - System Control
Table of Contents
Master file permissions, ownership, and process management on Linux Now that you can navigate and search, let’s learn to control the system: managing permissions and processes. When you run Permission meanings: Exercise 3.1: Symbolic method (easier to remember): Legend: Numeric method (faster when you know it): Calculate: Exercise 3.2: Common permission patterns: Requires sudo (root privileges): Exercise 3.3: See your groups: A process is a running program. Every command you run creates a process. Show running processes: Exercise 3.4: Understanding ps aux output: Interactive process monitor: Controls in Exercise 3.5: Common signals: Exercise 3.6: Exercise 3.7: Keep process running after logout: Uses a database (updated nightly): Exercise 3.8: Show disk usage: Exercise 3.9: Show directory sizes: Exercise 3.10: Ready to practice? Complete the hands-on challenge in the workshop repository: Challenge: Set up scripts with proper file permissions and create a system information script. The challenge includes: Clone the repository and give it a try:Navigation
Understanding File Permissions
ls -l, you see something like:-rw-r--r-- 1 bakayu users 1234 Nov 07 10:30 file.txt
│││││││││ │ │ │ │ │ └─ filename
│││││││││ │ │ │ │ └─ timestamp
│││││││││ │ │ │ └─ size
│││││││││ │ │ └─ group
│││││││││ │ └─ owner
│││││││││ └─ number of hard links
└┴┴┴┴┴┴┴┴─ permissionsPermission Breakdown
-rw-r--r--
│││ │││ │││
│││ │││ └┴┴─ others: read only
│││ └┴┴──── group: read only
│└┴──────── owner: read + write
└────────── file type (- = file, d = directory, l = link)r (read) = 4 w (write) = 2 x (execute) = 1 cd ~/workshop-practice
ls -l greeting.txt
# Decode what you see!Changing Permissions
chmod - Change Modechmod u+x file.sh # Add execute for user
chmod g-w file.txt # Remove write for group
chmod o+r file.txt # Add read for others
chmod a+x script.sh # Add execute for all
chmod u+rw,g+r file.txt # Multiple changesu = user (owner)g = groupo = othersa = all (ugo)+ = add permission- = remove permission= = set exactlychmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secret.txt # rw-------
chmod 777 public.txt # rwxrwxrwx (dangerous!)r=4, w=2, x=1, then add:755 = rwxr-xr-x = (4+2+1)(4+0+1)(4+0+1)644 = rw-r--r-- = (4+2+0)(4+0+0)(4+0+0)cd ~/workshop-practice
# Create a script
cat > hello.sh << 'EOF'
#!/bin/bash
echo "Hello from a script!"
EOF
# Try to run it
./hello.sh # Permission denied!
# Make it executable
chmod +x hello.sh
ls -l hello.sh
./hello.sh # Now it works!
# Make it read-only
chmod 444 hello.sh
ls -l hello.sh
# Try to edit it - you'll need sudo!755 - Scripts, executables644 - Regular files (documents, configs)600 - Private files (SSH keys, passwords)700 - Private directorieschown - Change Ownersudo chown user file.txt # Change owner
sudo chown user:group file.txt # Change owner and group
sudo chown -R user:group folder/ # Recursivecd ~/workshop-practice
touch myfile.txt
ls -l myfile.txt
# This will likely fail (unless you're root):
# sudo chown root myfile.txt
# sudo chown $USER myfile.txt # Change backchgrp - Change Groupchgrp groupname file.txt
chgrp -R groupname folder/groups # Your current groups
id # Detailed user infoProcess Management
ps - Process Statusps # Your processes in current terminal
ps -u username # All processes for a user
ps aux # All processes, detailed
ps aux | grep "firefox" # Find specific processps
ps aux
ps aux | grep "bash"USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 16832 1234 ? Ss 10:00 0:01 /sbin/init
│ │ │ │ │ │ │ │ │ │ └─ command
│ │ │ │ │ │ │ │ │ └─ CPU time
│ │ │ │ │ │ │ │ └─ start time
│ │ │ │ │ │ │ └─ state (S=sleeping, R=running)
│ │ │ │ │ │ └─ terminal
│ │ │ │ │ └─ memory (KB)
│ │ │ │ └─ virtual memory
│ │ │ └─ % of RAM
│ │ └─ % of CPU
│ └─ Process ID
└─ Usertop / htop - Live Process Viewertop # Basic monitor
htop # Better alternative (may need to install)top:q - Quitk - Kill process (prompts for PID)M - Sort by memoryP - Sort by CPUh - Helptop
# Press 'M' to sort by memory
# Press 'q' to quitkill - Terminate Processkill PID # Polite shutdown (SIGTERM)
kill -9 PID # Force kill (SIGKILL)
killall process_name # Kill all instances by name
pkill pattern # Kill by pattern match15 (SIGTERM) - Default, graceful shutdown9 (SIGKILL) - Force kill immediately1 (SIGHUP) - Reload config2 (SIGINT) - Interrupt (like Ctrl+C)# Start a long-running process in background
sleep 300 &
echo $! # Shows the PID
# Find it
ps aux | grep "sleep"
# Kill it (replace 12345 with actual PID)
kill 12345
# Verify it's gone
ps aux | grep "sleep"Background Jobs
command & # Run in background
jobs # List background jobs
fg # Bring to foreground
bg # Resume in background
Ctrl+Z # Suspend current job# Start in background
sleep 100 &
# List jobs
jobs
# Start another, then suspend it
sleep 200
# Press Ctrl+Z
# List jobs again
jobs
# Resume in background
bg
# Kill all background jobs
kill $(jobs -p)nohup - No Hangupnohup long_script.sh &
# Output goes to nohup.outFile Searching (Advanced)
locate - Fast File Searchlocate filename
locate "*.conf"
sudo updatedb # Update the database manuallywhich - Find Executable Locationwhich python
which ls
which codewhich bash
which git
which nonexistent # No output if not foundwhereis - Find Binary, Source, Manualwhereis python
whereis lsSystem Information
df - Disk Freedf # All filesystems
df -h # Human-readable
df -h /home # Specific mountdf -hdu - Disk Usagedu -sh folder/ # Summary of folder
du -h folder/ # All files/folders
du -sh */ # All subdirectories
du -h --max-depth=1 # One level deepcd ~
du -sh Documents/
du -sh */
du -h --max-depth=1 | sort -hfree - Memory Usagefree # Memory info
free -h # Human-readable
free -m # In megabytesuname - System Infouname -a # All info
uname -r # Kernel version
uname -m # ArchitectureHands-On Challenge
git clone https://github.com/bakayu/linux-tutorial.git
cd linux-tutorial/03-permissions-processes
./setup.sh
cat README.mdQuick Reference Card
# Permissions
ls -l # View permissions
chmod +x file # Add execute
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secret.txt # rw-------
sudo chown user file # Change owner
# Processes
ps aux # All processes
top # Live monitor
kill PID # Terminate process
kill -9 PID # Force kill
killall name # Kill by name
jobs # Background jobs
fg / bg # Foreground/background
# System Info
df -h # Disk usage
du -sh folder/ # Folder size
free -h # Memory usage
which command # Find executable
uname -a # System info