Cheat SheetsLinux Administration Learner Cheatsheet

Linux Administration — Learner Cheat Sheet

Topic Summary

Linux is a secure, multi-user operating system that uses permissions, systemd services, and process isolation to manage server resources. This cheat sheet covers the essential commands to manage users, file permissions, running processes, system services, networking, packages, and bash automation.

Key Concepts

  • User & Group IDs (UID/GID): Linux tracks users by ID numbers. root is UID 0 (master administrator). Standard users are UID 1000+.
  • sudo (Superuser Do): Allows standard users to temporarily elevate their privileges to execute administrative commands securely and auditably.
  • Process (PID): A running instance of a program, tracked by a Process ID. systemd is always PID 1.
  • Systemd (Daemon Manager): The master init system that launches and manages background services (daemons).
  • Package Manager (apt/dnf): Automates the installation, upgrading, and dependency resolution of software from centralized repositories.
  • Shebang (#!/bin/bash): The first line of a bash script that tells the kernel which interpreter to use.

Important Files & Directories

  • /etc/passwd: Master list of all user accounts on the server.
  • /etc/shadow: Encrypted password hash file (requires sudo).
  • /etc/sudoers: Policy file defining which users/groups can use sudo (edit ONLY with sudo visudo).
  • /usr/lib/systemd/system/ (or /etc/systemd/system/): Directory containing systemd unit (.service) configuration files.

User & Group Administration

TaskCommandMemory Aid / Note
View active identityid [username]Prints your active UID, GID, and secondary groups.
Create usersudo useradd -m -s /bin/bash username-m makes the home dir; -s sets default shell.
Add user to groupsudo usermod -aG groupname username-aG = append to Group.
Delete usersudo userdel -r username-r completely removes their home directory.

Related Lesson: MOD-LINUX-ADM-01

File Permissions & Ownership

TaskCommandMemory Aid / Note
Add execute permissionchmod u+x script.shuser + x (execute).
Set standard directorychmod 755 folder/rwxr-xr-x (User:7, Group:5, Others:5).
Set secure secrets filechmod 600 key.pemrw------- (User:6). Mandatory for SSH keys!
Change owner & groupsudo chown user:group fileChanges both owner and group simultaneously.

[!CAUTION] Never use chmod 777 to fix permission issues! It grants read/write/execute to everyone in the world and destroys system security.

Related Lesson: MOD-LINUX-ADM-02

Process & Job Management

TaskCommandMemory Aid / Note
Find running processps aux | grep process_nameTakes a static snapshot of all processes.
View live resourcestop or htopReal-time CPU/Memory monitor. (Press q to quit).
Run in background[command] &Adds job to background, returning your prompt.
Polite shutdownkill [PID]Sends SIGTERM to safely shut down a process.

[!CAUTION] Avoid using kill -9 [PID] (SIGKILL) unless a process is completely frozen. It forces instant termination without saving data or closing database connections cleanly.

Related Lesson: MOD-LINUX-ADM-03

Service Management (systemctl)

TaskCommandMemory Aid / Note
Check service healthsystemctl status [service]Displays active status and recent logs.
Start / Stop servicesudo systemctl start|stop [service]Powers the daemon on or off.
Reload config safelysudo systemctl reload [service]Re-reads configuration without dropping active users.
Enable on bootsudo systemctl enable [service]Service will start automatically when server turns on.
View live logssudo journalctl -u [service] -f-f (follow) streams live log output to screen.

Related Lesson: MOD-LINUX-ADM-04

Networking Basics

TaskCommandMemory Aid / Note
View IP addressesip addr showReplaces the deprecated ifconfig.
Test connectivityping -c 4 [hostname]-c 4 sends exactly 4 packets (prevents infinite loop).
View listening portssudo ss -tulpntcp, udp, listening, process, numeric.
Fetch HTTP headerscurl -I http://example.com-I fetches headers only (e.g., HTTP 200 OK).

Related Lesson: MOD-LINUX-ADM-05

Package Management (APT)

TaskCommandMemory Aid / Note
Update catalog cachesudo apt updateDo this before installing anything!
Install non-interactivesudo apt install -y [package]-y auto-answers “yes”, crucial for scripts.
Upgrade installed appssudo apt upgrade -yUpgrades software based on updated catalog.

Related Lesson: MOD-LINUX-ADM-06

Bash Scripting Automation

#!/bin/bash
set -euo pipefail # Strict safety: Abort on errors or undefined variables
 
BACKUP_DIR="/tmp/backup" # No spaces around equals sign!
 
if [ ! -d "$BACKUP_DIR" ]; then # Mandatory spaces inside brackets [ ]
    mkdir -p "$BACKUP_DIR"
fi
 
for SERVER in "app-01" "app-02"; do
    echo "Processing $SERVER..." # Double quotes interpolate variables
done
 
echo "Finished with exit code: $?" # $? holds the exit code of last command

Don’t forget to run chmod +x script.sh to make it executable!

Related Lesson: MOD-LINUX-ADM-07 Related Lab: LAB-MOD-LINUX-ADM-01

Common Beginner Mistakes

  • Using chmod 777: Destroys file security. Use chmod u+x for scripts, 600 for keys, 755 for directories.
  • Forgetting -y in apt install: Causes automated scripts (like Dockerfiles) to freeze indefinitely.
  • Spaces in Bash Variables: VAR = "hello" fails. Must be VAR="hello".
  • Missing sudo with ss -tulpn: Running ss -tulpn without sudo will hide the process names/PIDs owning the ports.
  • Confusing apt update with apt upgrade: update only refreshes the list of available software; upgrade actually updates the installed programs.