← All posts
Linux for DevOps: A Practical Guide for Beginners

Linux for DevOps: A Practical Guide for Beginners

Isreal UrephuNovember 23, 202619 min read

Linux is a fundamental skill for any DevOps engineer, and for almost any technical role. Your servers run Linux. Your Docker containers are Linux processes. Every Kubernetes node is a Linux machine. Your CI/CD runners are almost certainly Linux too. Sooner or later, something breaks on one of these machines and you are the one who has to SSH in and fix it.

The good news: you don't need to know Linux as deeply as a system administrator. You don't need to compile kernels or manage LDAP. You need to be comfortable and fast on the command line, and to know where to look when things go wrong.

This guide is step 1 of the DevOps roadmap. It covers exactly what to learn, the commands you'll actually use on the job, and a small exercise for each section.

How to use this guide: don't just read it. Spin up a free Linux VM (or use WSL on Windows, or a cheap cloud instance) and type every command as you go. Muscle memory is the whole point.

What to learn (and what to skip)

Learn this wellKnow it exists, don't go deep
Navigating the filesystemKernel compilation and tuning
Permissions and ownershipSELinux / AppArmor policy writing
SSH and remote serversAdvanced iptables / nftables rules
Processes and signalsLVM, RAID and filesystem internals
Package managers and systemdMail servers, LDAP, printing
Basic networking commandsWriting large programs in Bash
Troubleshooting disk, memory and CPU
Bash scripting for automation

1. Understand Linux as a system

Before the commands, it helps to have a mental model of what Linux actually is.

Strictly speaking, Linux is a kernel: the core program that talks to the hardware (CPU, memory, disks, network cards). What you install, such as Ubuntu, Debian, Rocky or Amazon Linux, is a distribution: the kernel plus tools, a package manager and defaults.

linux for devops cover

A running Linux system is split into two worlds:

  • Kernel space: where the kernel runs, with full access to the hardware.
  • User space: where everything else runs: your shell, your apps, Python, Docker, nginx.

Programs in user space can't touch the hardware directly. When they need to open a file, send data over the network or start a new process, they ask the kernel through a system call (syscall). Syscalls are the bridge between the two worlds.

You can actually watch this happen:

bash
strace -c ls    # count every syscall that `ls` makes

Why this matters for DevOps: containers are not magic virtual machines. A container is just a normal Linux process that the kernel isolates using features called namespaces (what the process can see) and cgroups (how much CPU and memory it can use). Once that clicks, Docker and Kubernetes make far more sense. We'll come back to this in the Containers step.

2. Navigating the filesystem

These commands are your bread and butter. You will use them every single day as a DevOps engineer.

bash
pwd                     # where am I?
ls -la                  # list everything, including hidden files, with details
cd /var/log             # move to a directory
cd ~                    # go to your home directory
cd -                    # go back to the previous directory
mkdir -p app/config     # create a directory (and parents if needed)
touch app/config/app.env   # create an empty file
cp -r app app-backup    # copy a directory recursively
mv app.env app.env.old  # move or rename
rm -r app-backup        # delete (there is no recycle bin, so be careful)
cat file.txt            # print a file
less /var/log/syslog    # scroll through a big file (q to quit)
head -n 20 file.txt     # first 20 lines
tail -f /var/log/nginx/access.log   # follow a log live
find / -name "*.conf" 2>/dev/null   # find files by name
grep -rn "error" /var/log/          # search inside files

The Linux directory tree

Everything starts at / (the root of the filesystem). These are the directories you'll meet constantly:

DirectoryWhat lives there
/The top of the tree. Everything is under here.
/homeHome directories for normal users (/home/isreal).
/rootHome directory of the root user.
/etcSystem-wide configuration: /etc/nginx/, /etc/ssh/sshd_config, /etc/hosts.
/varData that changes: logs in /var/log, Docker data in /var/lib/docker.
/tmpTemporary files, often wiped on reboot.
/usrInstalled programs and libraries (/usr/bin, /usr/lib).
/optOptional, third-party software.
/procA virtual window into running processes and the kernel.
/devDevices, such as disks (/dev/sda) and /dev/null.

Everything is a file

In Linux, almost everything is represented as a file: config, logs, devices, even running processes. Try these:

bash
cat /proc/cpuinfo      # your CPU, as a file
cat /proc/meminfo      # memory stats, as a file
ls /proc/1/            # everything about process ID 1
echo "hello" > /dev/null   # the "black hole" device

This idea is why so much of DevOps work is just reading and editing text files.

Practise this: create a directory structure ~/practice/{logs,config,scripts}. Find every .conf file under /etc, then use grep to find which one mentions PermitRootLogin.

3. File permissions and ownership

You'll often hit Permission denied. Understanding why is essential.

Run ls -l and you'll see something like:

text
-rwxr-x---  1 deploy  devops  2048 Nov 20 10:00 deploy.sh

Break down -rwxr-x---:

  • The first character is the type: - for a file, d for a directory, l for a link.
  • Then three groups of three: user (owner) rwx, group r-x, others ---.
  • r = read, w = write, x = execute (for directories, x means "can enter").

So deploy can do everything, members of devops can read and run it, and everyone else gets nothing.

Changing permissions

Each permission has a number: r=4, w=2, x=1. Add them up per group:

bash
chmod 755 deploy.sh   # rwxr-xr-x: owner full, everyone else read + execute
chmod 644 config.yml  # rw-r--r--: owner read/write, everyone else read
chmod 600 id_ed25519  # rw-------: private keys must be owner-only
chmod +x deploy.sh    # make a script executable (symbolic form)
chmod -R g+w shared/  # give the group write access, recursively

Changing ownership

bash
sudo chown deploy deploy.sh           # change the owner
sudo chown deploy:devops deploy.sh    # change owner and group
sudo chown -R www-data:www-data /var/www/app   # recursively, e.g. for a web server

sudo runs a command as root. Use it when you need to, not by default.

Classic scenario: you write deploy.sh, run ./deploy.sh and get Permission denied. The file isn't executable. chmod +x deploy.sh fixes it.

Practise this: create a script, try to run it, fix the permission error. Then create a new user, make a file only that user can read, and confirm your normal user can't cat it.

4. SSH: working on remote servers

As a DevOps engineer, most servers you touch won't be in front of you. SSH (Secure Shell) is how you connect to them.

Connecting

bash
ssh ubuntu@203.0.113.10                  # connect as user "ubuntu"
ssh -i ~/.ssh/my-key.pem ubuntu@203.0.113.10   # with a specific key (common on AWS)
ssh -p 2222 ubuntu@203.0.113.10          # on a non-default port

Key-based authentication

Passwords are weak; keys are the standard. You generate a key pair: the private key stays on your laptop, and the public key goes on the server.

bash
ssh-keygen -t ed25519 -C "isreal@laptop"   # creates ~/.ssh/id_ed25519 and id_ed25519.pub
ssh-copy-id ubuntu@203.0.113.10            # copies your public key to the server

ssh-copy-id simply appends your public key to ~/.ssh/authorized_keys on the server. You can do it by hand too, but permissions must be strict or SSH will ignore the file:

bash
mkdir -p ~/.ssh && chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Giving a teammate access

bash
sudo adduser alice                    # create the user
sudo usermod -aG sudo alice           # optional: allow sudo (use "wheel" on RHEL-based systems)
sudo mkdir -p /home/alice/.ssh
sudo nano /home/alice/.ssh/authorized_keys   # paste Alice's PUBLIC key
sudo chown -R alice:alice /home/alice/.ssh
sudo chmod 700 /home/alice/.ssh && sudo chmod 600 /home/alice/.ssh/authorized_keys

Save time with ~/.ssh/config

text
Host web1
    HostName 203.0.113.10
    User ubuntu
    IdentityFile ~/.ssh/my-key.pem

Now ssh web1 is all you need.

Copying files

bash
scp app.tar.gz web1:/tmp/                 # copy a file to the server
rsync -avz ./site/ web1:/var/www/site/    # sync a directory (faster for repeat copies)

Port forwarding

Say a database or admin dashboard on the server only listens on localhost:5432, so it isn't exposed to the internet. You can still reach it safely through SSH:

bash
ssh -L 5432:localhost:5432 web1

Now connecting to localhost:5432 on your laptop goes through the tunnel to the server. This is perfect for testing connectivity without opening firewall ports.

Basic hardening

In /etc/ssh/sshd_config, once key login works:

text
PasswordAuthentication no
PermitRootLogin no

Then sudo systemctl restart ssh (named sshd on some distros). Keep your current session open until you've confirmed you can log in from a new terminal, or you can lock yourself out.

Practise this: create two VMs. Set up key-only SSH from one to the other, add a second user with their own key, and use -L to reach a web server on the remote machine that only listens on localhost.

5. Processes

As a DevOps engineer, you manage Linux processes all the time. Your application is a process. Your Python program is a process. Your Docker containers are processes. Your Kubernetes pods are processes too. Knowing how to inspect and control them is core.

Listing and finding processes

bash
ps aux                    # every process on the system
ps aux | grep nginx       # find a specific one
pgrep -a python           # find processes by name, with their command line
top                       # live view: CPU, memory, load (q to quit)
htop                      # a friendlier top (may need installing)

Every process has a PID (process ID) and a parent (PPID). pstree -p shows the family tree.

Stopping processes and signals

You stop a process by sending it a signal:

bash
kill 1234          # sends SIGTERM (15): "please shut down cleanly"
kill -9 1234       # sends SIGKILL (9): "stop now", no cleanup possible
pkill -f "gunicorn"   # kill by name or command line

Always try SIGTERM first. SIGKILL can't be caught, so the app never gets the chance to flush data or close connections. This matters in Kubernetes too: when a pod is deleted, it gets SIGTERM first, then SIGKILL after a grace period.

Background jobs

bash
./long-task.sh &           # run in the background
jobs                       # list background jobs
fg %1                      # bring job 1 back to the foreground
nohup ./long-task.sh &     # keep running after you log out

For anything long-lived in production, don't rely on nohup. Run it as a systemd service (next section).

Which port is a process using?

bash
sudo ss -tulpn                 # every listening port and the process behind it
sudo ss -tulpn | grep :8080    # who's on port 8080?
sudo lsof -i :8080             # same question, different tool

Practise this: run python3 -m http.server 8000 &. Find its PID three different ways (ps, pgrep, ss), then stop it with SIGTERM.

6. Installing packages and managing services

As a DevOps engineer, you'll install and manage software on servers: Docker, container runtimes, Prometheus exporters, nginx, monitoring agents and more.

Package managers

A package manager downloads software from trusted repositories, installs it with its dependencies, and keeps it updated. Which one you use depends on the distro family:

Distro familyPackage manager
Debian, Ubuntuapt
RHEL, Rocky, Fedora, Amazon Linuxdnf (older: yum)
Alpine (common in containers)apk
bash
sudo apt update                # refresh the list of available packages
apt search nginx               # find a package
sudo apt install -y nginx      # install it
sudo apt upgrade               # upgrade installed packages
sudo apt remove nginx          # remove it
 
sudo dnf install -y nginx      # the same idea on RHEL-family systems

Some tools (like Docker or Kubernetes packages) need you to add the vendor's own repository first. Always follow the official install docs for those.

systemd and systemctl

Most modern distros use systemd to start and supervise services. systemctl is how you control it:

bash
sudo systemctl start nginx      # start now
sudo systemctl stop nginx       # stop
sudo systemctl restart nginx    # restart (e.g. after a config change)
sudo systemctl reload nginx     # reload config without dropping connections
sudo systemctl enable nginx     # start automatically on boot
sudo systemctl enable --now nginx   # enable and start in one go
systemctl status nginx          # is it running? recent logs too
systemctl list-units --type=service --state=failed   # what's broken?

When a service won't start, the logs are in the journal:

bash
journalctl -u nginx             # all logs for nginx
journalctl -u nginx -f          # follow live
journalctl -u nginx --since "10 min ago"

Practise this: install nginx, enable it on boot, confirm it with curl localhost, reboot the VM, and confirm it came back on its own. Then break its config on purpose, try to restart, and use journalctl to find the error.

7. Networking on the box

Networking gets its own step in the roadmap. Here is the foundation you need on any Linux machine.

bash
ip a                     # network interfaces and their IP addresses
ip route                 # routing table, including the default gateway
sudo ss -tulpn           # open (listening) ports and which process owns them
ping -c 4 8.8.8.8        # can I reach that IP at all?
dig google.com           # DNS lookup (or: nslookup google.com)
curl -v http://localhost:8080/health   # make an HTTP request and see the details
cat /etc/hosts           # local hostname overrides

Binding to an address

When an app listens on a port, it also binds to an address. This catches people out constantly:

  • 127.0.0.1:8080 means only reachable from the same machine.
  • 0.0.0.0:8080 means reachable on all interfaces, including from outside.

If your app works with curl localhost:8080 on the server but not from your laptop, check ss -tulpn. It's probably bound to 127.0.0.1. Also, ports below 1024 (like 80 and 443) need root privileges to bind.

Firewalls (just the basics)

On Ubuntu, ufw is the friendly option:

bash
sudo ufw allow OpenSSH       # don't lock yourself out!
sudo ufw allow 80/tcp
sudo ufw enable
sudo ufw status

Under the hood this is iptables / nftables. Know they exist, but don't go too deep. In the cloud, you'll mostly use security groups instead.

Practise this: run a simple web server bound to 127.0.0.1, prove you can't reach it from another machine, rebind it to 0.0.0.0, then use ufw to allow only port 80.

8. Resource management and troubleshooting

At some point, a server will run out of disk, run out of memory, or slow to a crawl, and you need to find out why and bring it back. This is one of the most valuable skills you can have on call.

Disk

bash
df -h                          # disk usage per filesystem
du -sh /var/* | sort -h        # which directories are biggest?
du -sh /var/log/* | sort -h    # usually the culprit: logs

Gotcha: the disk is full but you can't find the files. If a process still has a deleted file open (often a huge log), the space isn't freed until that process lets go:

bash
sudo lsof +L1      # list deleted files that are still open

Restart that process, or truncate the file instead of deleting it. To empty a huge log safely while the app keeps writing to it:

bash
sudo truncate -s 0 /var/log/myapp/app.log   # empty it in place

Using rm on a log that's still open frees nothing until the process restarts.

Memory

bash
free -h                     # total, used and available memory
top                         # press M to sort by memory
ps aux --sort=-%mem | head  # top memory users

Look at available, not "free". Linux uses spare memory for caching, and that's a good thing. If memory runs out completely, the kernel's OOM killer picks a process and kills it:

bash
sudo dmesg -T | grep -i "killed process"   # did the OOM killer strike?

CPU and load

bash
uptime            # load average over 1, 5 and 15 minutes
top               # press P to sort by CPU
nproc             # number of CPU cores

A load average consistently higher than your number of cores means work is queuing up.

File descriptors

Every open file, socket and connection uses a file descriptor, and there are limits. Busy apps can hit them and fail with Too many open files:

bash
ulimit -n                      # the limit for your shell
ls /proc/1234/fd | wc -l       # how many process 1234 has open

A quick "server is unhealthy" checklist

  1. uptime: is load high?
  2. df -h: is a disk full?
  3. free -h: is memory exhausted? Check dmesg for OOM kills.
  4. top: which process is eating CPU or memory?
  5. systemctl status <service> and journalctl -u <service>: what does the app say?
  6. ss -tulpn: is it still listening on its port?

Practise this: fill a disk on purpose with fallocate -l 2G bigfile, find it with du, and clean it up. Then write a tiny script that leaks memory and watch it with top until the OOM killer steps in.

9. Bash scripting

Once you're comfortable on the command line, the next step is automating what you do by hand. Bash scripts glue DevOps work together: setup scripts, health checks, backups, CI pipeline steps and container entrypoints.

Your first script

bash
#!/usr/bin/env bash
set -euo pipefail
 
echo "Hello from $(hostname)"
  • The first line (the shebang) says which interpreter runs the script.
  • set -euo pipefail makes the script stop on errors, treat unset variables as errors, and catch failures inside pipes. Put it at the top of every script.

Save it as hello.sh, then chmod +x hello.sh && ./hello.sh.

The building blocks

bash
# Variables (no spaces around =), and always quote them
NAME="barilon"
echo "Deploying ${NAME}"
 
# Arguments passed to the script
ENVIRONMENT="${1:-staging}"   # first argument, default "staging"
echo "All arguments: $@"
 
# Command substitution
TODAY=$(date +%F)
 
# Conditions
if [[ -f /etc/nginx/nginx.conf ]]; then
  echo "nginx is configured"
elif [[ "$ENVIRONMENT" == "prod" ]]; then
  echo "prod without nginx config!"
else
  echo "nothing to do"
fi
 
# Loops
for server in web1 web2 web3; do
  ssh "$server" "uptime"
done
 
while read -r line; do
  echo "Line: $line"
done < servers.txt
 
# Functions
log() {
  echo "[$(date +%T)] $*"
}
log "Starting backup"

Exit codes, pipes and redirection

Every command returns an exit code: 0 means success, anything else means failure. That's how scripts and CI pipelines know whether something worked.

bash
grep -q "ERROR" app.log
echo $?                         # 0 if found, 1 if not
 
./deploy.sh > deploy.log        # stdout to a file (overwrite)
./deploy.sh >> deploy.log       # append
./deploy.sh > deploy.log 2>&1   # stdout AND errors to the file
cat access.log | grep 500 | wc -l   # pipes: chain commands together

Scheduling with cron

bash
crontab -e
text
# minute hour day month weekday  command
*/5 * * * * /opt/scripts/disk-check.sh >> /var/log/disk-check.log 2>&1
0 2 * * *   /opt/scripts/backup.sh

A real example: disk usage alert

This ties the last section together. It checks every filesystem and warns when one is above a threshold:

bash
#!/usr/bin/env bash
set -euo pipefail
 
THRESHOLD="${1:-80}"   # percent; pass a different value as the first argument
STATUS=0
 
while read -r usage mount; do
  percent="${usage%\%}"   # strip the % sign
  if (( percent >= THRESHOLD )); then
    echo "WARNING: ${mount} is at ${usage}"
    STATUS=1
  fi
done < <(df -h --output=pcent,target -x tmpfs -x devtmpfs | tail -n +2)
 
if (( STATUS == 0 )); then
  echo "All filesystems below ${THRESHOLD}%"
fi
exit "$STATUS"

It exits with 1 when any disk is too full, so you can run it from cron, a CI job or a monitoring check and act on the result.

What to skip

Don't try to become a Bash wizard. When a script grows past about 100 lines, needs real data structures, or has to call APIs and parse JSON, reach for Python instead. Bash is for gluing commands together; it isn't a general programming language.

Practise this: write a script that takes a service name as an argument, checks whether it's running with systemctl is-active, restarts it if not, and logs what it did with a timestamp. Schedule it with cron every five minutes.

Mini project

Time to put it all together on a real server.

Deploy and manage a real web application on a Linux server, using everything from this guide: SSH, users and permissions, packages, systemd, networking, troubleshooting and a Bash script to tie it together.

👉 Start the project: Linux Fundamentals — Deploy and Manage a Web Application

Interview questions you should be able to answer

If you've worked through this guide, you should be able to answer these confidently:

  1. What happens, step by step, when you type ls and press Enter?
  2. What's the difference between permissions 755 and 644, and when would you use each?
  3. A service won't start after a config change. Walk me through how you'd debug it.
  4. How do you find which process is listening on port 80?
  5. df says the disk is 100% full, but du doesn't add up. What's going on?
  6. What's the difference between SIGTERM and SIGKILL?
  7. What does set -euo pipefail do, and why use it?

Want the full answers, plus more Linux and DevOps questions? Head to Interview Prep →

Prefer to practise out loud? Book a mock interview and get feedback before the real one.

What's next

You've got the foundation every other step builds on. Next on the roadmap is Networking: TCP/IP, DNS, HTTP, load balancing and how traffic really flows between machines.

👉 See the full DevOps roadmap

Newsletter

Enjoyed this article?

Get new posts in your inbox.

No spam. Unsubscribe anytime.