Linux: Your Magic Workshop
The operating system that runs 96% of the world's servers.
What you'll learn in this chapter
- Why Linux is the foundation of nearly all modern infrastructure
- How the Linux file system is organized โ and why "everything is a file"
- The 20 essential commands every DevOps engineer uses daily
- File permissions: reading, writing, executing, and who is allowed to do what
- Managing services with systemctl
- Installing software with package managers
- Connecting to remote machines securely with SSH
The Workshop Analogy
Imagine a master craftsman's workshop. Every tool has its place. The chisels are on the left wall, the saws on the right, the measuring tape always hanging by the door. The floor is swept clean every evening. The workbench has space for the project at hand, and nothing else. When you walk into that workshop, you feel the accumulated order of years of deliberate practice. You could build almost anything in there โ furniture, musical instruments, a boat โ as long as you know where the tools are and how to use them.
Linux is that workshop.
Windows is a shopping mall: beautiful, bright, designed to guide customers through the experience without them needing to think. It is excellent for consumers. Linux is designed for builders. It does not hold your hand. It does not ask you if you're sure. But it gives you total control, complete transparency, and tools of extraordinary power โ once you know where they are.
If your application runs at any scale on the internet, it almost certainly runs on Linux. Google, Amazon, Facebook, Netflix, every major bank's backend, and essentially every cloud server you will ever provision in your career runs Linux. Learning Linux is not optional for a DevOps engineer โ it is as fundamental as learning to walk before you run.
The Linux File System โ Everything is a File
Linux has a radical and elegant philosophy: everything is a file. Your documents are files. Your programs are files. Your hardware devices โ your hard drive, your keyboard, your network interface โ are represented as files. Even running processes have file representations. This consistency is not just philosophical; it means you can use the same tools to interact with almost anything on the system.
The file system is organized as a single tree, starting from the root directory /
(pronounced "slash" or "root"). Unlike Windows, which has multiple drives (C:, D:, etc.),
Linux has one tree, and everything hangs from it.
Here are the directories you will encounter constantly:
/ โ Root of the entire file system โโโ home/ โ โโโ ubuntu/ โ Your personal home directory โโโ etc/ โ System and application configuration files โโโ var/ โ โโโ log/ โ Log files โ where apps write their diaries โโโ tmp/ โ Temporary files (deleted on reboot) โโโ usr/ โ โโโ bin/ โ Programs you can run (ls, grep, curl...) โโโ bin/ โ Essential system programs โโโ proc/ โ Live info about running processes (virtual) โโโ dev/ โ Device files (hard drives, USB, etc.) โโโ opt/ โ Optional, third-party software
A few of these deserve special attention. /etc is where almost all
configuration files live โ when you want to change how Nginx serves traffic, or how
PostgreSQL authenticates users, you edit files in /etc. The name "etc" is
a legacy from Unix history, but think of it as the settings drawer of your workshop.
/var/log is where your applications write their diary entries. When something
goes wrong in production and you need to find out what happened, you will spend a lot of
time in /var/log. The /proc directory is particularly magical โ
it is not a real directory on disk, but a virtual window into the running kernel. Reading
/proc/meminfo tells you the current memory state of the system in real time.
A path is the address of a file or directory in the file system.
An absolute path starts from root: /home/ubuntu/projects/app.js.
A relative path is relative to where you currently are: if you're already
in /home/ubuntu, then projects/app.js is the relative path to the same file.
The 20 Commands You Must Know
You do not need to memorize hundreds of commands on day one. These twenty will take you through the vast majority of your daily work as a DevOps engineer. Master these before moving on.
Navigation
Before you can do anything, you need to know where you are and how to move around.
# Where am I right now?
pwd
# Output: /home/ubuntu
# What files and folders are here?
ls
# List everything, including hidden files, with details
ls -la
# Go to a directory
cd /var/log
# Go up one level
cd ..
# Go to your home directory (shortcut)
cd ~
# Go to the previous directory you were in
cd -
The output of ls -la deserves a moment of explanation. Each line looks like this:
-rwxr-xr-x 1 ubuntu ubuntu 4096 May 3 09:14 deploy.sh
Reading left to right: file type and permissions, number of hard links, owner, group, size in bytes, last modified date, and filename. We will cover the permissions string in detail shortly.
Working with Files
# Create a new directory
mkdir my-project
# Create nested directories in one command
mkdir -p my-project/src/utils
# Create an empty file
touch README.md
# Copy a file
cp config.env config.env.backup
# Copy a directory and all its contents
cp -r my-project/ my-project-backup/
# Move or rename a file
mv old-name.txt new-name.txt
# Delete a file (careful โ there is no recycle bin)
rm unwanted.txt
# Delete a directory and everything inside it
rm -rf old-project/
# Print the contents of a file to the terminal
cat .env
Viewing File Contents
# Page through a large file (press q to quit, space to advance)
less /var/log/nginx/access.log
# See just the first 20 lines of a file
head -n 20 application.log
# Watch a log file grow in real time (essential for debugging)
tail -f /var/log/myapp/app.log
# Search for a pattern in a file
grep "ERROR" application.log
# Search recursively through a directory
grep -r "database_url" /etc/myapp/
# Case-insensitive search
grep -i "error" application.log
tail -f is one of the most used commands in production debugging. The -f
flag means "follow" โ the terminal keeps the file open and prints new lines as they are appended.
When something is going wrong and you need to watch the logs in real time, this is your tool.
System Information
# List all running processes in detail
ps aux
# Find a specific process by name
ps aux | grep nginx
# Stop a process (replace PID with the process ID number)
kill 1234
# Force-kill a process that won't stop
kill -9 1234
# Live view of CPU and memory usage
top
# A nicer version of top (must install: sudo apt install htop)
htop
# Disk usage of all mounted filesystems, human-readable
df -h
# How much memory is available
free -h
Never run rm -rf / or rm -rf /*. These commands delete your
entire file system, starting from root, with no confirmation and no recovery. Linux
will not ask "Are you sure?" It will simply execute. Some systems have a --no-preserve-root
safeguard, but do not rely on it. Any time you use rm -rf, double-check
the path. Triple-check it.
File Permissions Explained
Linux takes security seriously, and file permissions are the foundation of that security. Every file and directory has three sets of permissions: what the owner can do, what members of the group can do, and what everyone else can do.
The permission string looks like this: -rwxr-xr-x
- rwx r-x r-x โ โ โ โ โ โ โ โโโ Others: read + execute, no write โ โ โโโโโโโโ Group: read + execute, no write โ โโโโโโโโโโโโโ Owner: read + write + execute โโโโโโโโโโโโโโโโโ File type: - = file, d = directory, l = symlink r = read (4) w = write (2) x = execute (1) - = no permission (0)
The numbers in parentheses are important. Permissions are often set using numeric codes, where each digit is the sum of the permissions for that group:
chmod 755 script.shโ owner can read/write/execute (7=4+2+1), group and others can read/execute (5=4+1). Standard for scripts.chmod 644 config.txtโ owner can read/write (6=4+2), group and others can only read (4). Standard for config files.chmod 600 id_rsaโ only the owner can read/write (6), nobody else can do anything. Required for SSH private keys โ SSH will refuse to use a key with looser permissions.chmod 777 fileโ everyone can do everything. Almost always a bad idea in production.
# Set permissions numerically
chmod 755 deploy.sh
# Add execute permission for the owner
chmod u+x deploy.sh
# Change the owner of a file
chown ubuntu:ubuntu /var/www/myapp
# Change ownership recursively (all files in a directory)
chown -R ubuntu:ubuntu /var/www/myapp
Processes and Services
A process is a running program. When you start Nginx, a process appears. When Nginx handles a request, that process does the work. Every process has a unique number called a PID (Process ID), which is how you refer to it when you want to stop, pause, or signal it.
On modern Linux systems, long-running background programs (called services or
daemons) are managed by a tool called systemd, controlled via
the systemctl command. This is the command you will use to start, stop,
and check on services like web servers, databases, and your own applications.
# Start a service
systemctl start nginx
# Stop a service
systemctl stop nginx
# Restart a service (stop then start)
systemctl restart nginx
# Reload config without full restart (if supported)
systemctl reload nginx
# Enable a service to start automatically on boot
systemctl enable nginx
# Disable automatic startup on boot
systemctl disable nginx
# Check if a service is running
systemctl status nginx
# See recent logs for a service
journalctl -u nginx --since "1 hour ago"
The systemctl status command is your first stop when investigating a
production issue. It shows whether the service is running, its PID, recent log lines,
and whether it exited cleanly or crashed.
Package Management
Installing software on Linux is done through a package manager โ a tool that downloads, installs, and keeps track of software packages from trusted repositories. There is no hunting for .exe files or double-clicking installers. One command, and the software is installed with all its dependencies.
There are two main families of package managers you will encounter in DevOps:
# --- Ubuntu / Debian (used by most cloud servers, Docker base images) ---
# Update the package index (always do this before installing)
sudo apt update
# Install a package
sudo apt install nginx
# Install multiple packages at once
sudo apt install nginx curl git vim
# Remove a package
sudo apt remove nginx
# Remove package and its configuration files
sudo apt purge nginx
# Upgrade all installed packages
sudo apt upgrade
# --- RHEL / CentOS / Amazon Linux (used on many enterprise servers) ---
sudo yum install nginx
sudo dnf install nginx # newer systems use dnf
On Ubuntu/Debian, always run sudo apt update before installing anything.
This refreshes the local list of available packages. Without it, apt might install an
older version of a package or fail to find a new one entirely. Make it a habit:
sudo apt update && sudo apt install <package>.
SSH โ Talking to Remote Machines
In DevOps, you rarely work on a machine that is sitting in front of you. You work on servers in data centers, cloud instances in AWS or GCP, and VMs that may be thousands of kilometers away. The way you connect to these machines is through SSH โ Secure Shell.
Think of SSH as making a secure phone call to another computer. Once connected, you get a terminal prompt on that remote machine. Every command you type executes there, not on your local machine. You see the output. You can do anything you would do if you were physically sitting at that machine's keyboard.
# Connect to a remote server using a username and password
ssh ubuntu@192.168.1.100
# Connect using an SSH key file (the standard way for cloud servers)
ssh -i ~/.ssh/my-key.pem ubuntu@192.168.1.100
# Connect to a non-standard port (default is 22)
ssh -p 2222 ubuntu@192.168.1.100
# Copy a file from your machine to a remote server
scp config.env ubuntu@192.168.1.100:/var/www/myapp/
# Copy a file FROM a remote server to your local machine
scp ubuntu@192.168.1.100:/var/log/app.log ./app.log
# Generate an SSH key pair (do this once on your machine)
ssh-keygen -t ed25519 -C "yourname@example.com"
SSH Keys: Why Passwords Are Not Enough
When you connect to a server with a password, that password travels over the network (encrypted, but still). It can be brute-forced. It can be leaked. It can be reused. SSH keys are more secure because they use public-key cryptography.
Here is how it works. You generate a key pair: a private key (which stays on your machine, never shared with anyone) and a public key (which you copy to the server). When you connect, the server uses the public key to challenge you, and only your private key can respond correctly. No password is ever transmitted.
# Generate an Ed25519 key pair (modern, fast, secure)
ssh-keygen -t ed25519 -C "ubuntu@myserver"
# This creates:
# ~/.ssh/id_ed25519 (private key โ guard this with your life)
# ~/.ssh/id_ed25519.pub (public key โ copy this to servers)
# Copy your public key to a remote server (enables key-based login)
ssh-copy-id ubuntu@192.168.1.100
# Manually add your public key to the server's authorized_keys
cat ~/.ssh/id_ed25519.pub | ssh ubuntu@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Your private key (~/.ssh/id_ed25519) is like the master key to every
server you have added it to. Never commit it to Git. Never share it in a chat message.
Never put it in your application's code. If it is compromised, regenerate your key
pair immediately and remove the old public key from every server.
Useful Tips for the Terminal
A few habits that will make you dramatically faster in the terminal:
- Tab completion: Press Tab while typing a command or path to auto-complete. Press it twice to see all options.
- History: Press the up arrow to scroll through previous commands. Run
historyto see your full history. UseCtrl+Rto search through it. - Ctrl+C: Cancel the currently running command. Use this when a command hangs.
- Ctrl+L: Clear the terminal screen (same as the
clearcommand). - Pipe (
|): Send the output of one command as the input to another. For example:ps aux | grep nginx. - Redirect (
>): Write command output to a file:ls -la > files.txt. - Append (
>>): Append output to a file without overwriting:echo "done" >> deploy.log.
As of 2026, Linux runs on over 96% of the world's top web servers, 100% of the world's fastest supercomputers, and all of Amazon, Google, and Microsoft's cloud infrastructure. Android โ the world's most-used mobile operating system โ is built on a Linux kernel. The International Space Station runs Linux. So does the Mars rover. When you learn Linux, you are learning the language of the machines that run the planet.
Chapter Summary
- Linux is the operating system of the internet. Nearly every server you work with in DevOps runs Linux.
- Everything in Linux is a file โ documents, devices, processes. One consistent interface to interact with everything.
- The file system is a single tree starting at
/. Key directories:/etc(configs),/var/log(logs),/usr/bin(programs),/home(users). - The 20 essential commands cover navigation, file management, viewing content, system information, and permissions.
- File permissions control who can read, write, and execute each file.
chmodandchownmanage them. systemctlmanages services โ starting, stopping, enabling on boot, and checking status.- SSH is how you connect to remote machines. Use key-based authentication, never just passwords.