DEV Community

Shivakumar
Shivakumar

Posted on

Linux Operating System – Complete DevOps Study Notes

This is a comprehensive request covering the full spectrum of Linux administration, specifically tailored for DevOps. Because this covers an entire curriculum, I have structured this as a High-Impact Reference Guide.

This guide is organized logically from Core Fundamentals to Advanced Administration & Security.


Part 1: Linux Fundamentals & Architecture

1. What is Linux?

Linux is an open-source, Unix-like operating system kernel. In a DevOps context, "Linux" usually refers to a distribution (Distro) like Ubuntu, CentOS, or Alpine which includes the kernel, system utilities, and a package manager.

  • Kernel: The core that manages CPU, Memory, and I/O.
  • Shell: The interface (CLI) between the user and the kernel (e.g., Bash, Zsh).
  • Userspace: Where applications run.

2. Linux File System Hierarchy

Linux uses a single hierarchical tree structure, starting at the root /.

  • / (Root): The starting point of the file system.
  • /bin & /usr/bin: Essential user binaries (commands like ls, cp).
  • /etc: Configuration files (e.g., /etc/nginx/nginx.conf).
  • /home: User home directories (e.g., /home/john).
  • /var: Variable data (logs, spool files, temporary e-mail files).
  • /tmp: Temporary files (deleted on reboot).
  • /proc: Virtual filesystem providing process and kernel information.

Part 2: Essential File Management & Permissions

1. File Management Commands

  • Navigation: pwd (print working directory), cd (change directory), ls -la (list all files with details).
  • Manipulation:
  • touch file: Create empty file.
  • mkdir -p dir/subdir: Create directory (and parents if needed).
  • cp -r source dest: Copy files/directories recursively.
  • mv source dest: Move or Rename.
  • rm -rf path: Force remove directory and contents (Use with caution).
  • cat, less, head, tail: View file contents.

2. File Permissions

Linux permissions are divided into User (u), Group (g), and Others (o).

The Modes:

  • Read (r) = 4
  • Write (w) = 2
  • Execute (x) = 1

Common Commands:

  • chmod 755 file: Owner (rwx=7), Group (rx=5), Others (rx=5).
  • chmod +x script.sh: Make a file executable.
  • chown user:group file: Change ownership.
  • chgrp group file: Change group ownership.

Part 3: User, Group, and Package Management

1. User & Group Management

DevOps often requires creating isolated users for services.

  • Files:
  • /etc/passwd: User info.
  • /etc/shadow: Secure password hashes.
  • /etc/group: Group info.

  • Commands:

  • useradd -m -s /bin/bash username: Create user with home dir and bash shell.

  • usermod -aG sudo username: Add user to the 'sudo' group.

  • passwd username: Set password.

  • id username: Show user ID and group IDs.

2. Package Management

Different distros use different managers.

Distro Family Package Manager Install Command Update Command
Debian/Ubuntu apt apt install package apt update && apt upgrade
RHEL/CentOS yum / dnf yum install package yum update
Alpine apk apk add package apk update

Part 4: Networking & Firewall

1. Network Configuration & Troubleshooting

  • ip addr show: Display IP addresses (modern replacement for ifconfig).
  • ip route: Show routing table.
  • ping <host>: Check connectivity.
  • curl -I <url>: Check header response from a web server.
  • wget <url>: Download files.
  • nslookup domain.com / dig domain.com: DNS troubleshooting.
  • netstat -tulpn or ss -tulpn: Check listening ports (Critical for debugging why a service isn't reachable).

2. Linux Firewalls

  • UFW (Ubuntu): Simple wrapper.
  • ufw allow 22/tcp: Allow SSH.
  • ufw enable: Turn on firewall.

  • firewalld (CentOS/RHEL):

  • firewall-cmd --permanent --add-port=80/tcp

  • firewall-cmd --reload

  • iptables: The legacy, low-level tool for table-based packet filtering.


Part 5: Processes, Systemd, and Boot

1. The Boot Process

  1. BIOS/UEFI: Hardware check, loads bootloader.
  2. Bootloader (GRUB): Loads the Kernel.
  3. Kernel: Mounts root filesystem, starts init.
  4. Init (Systemd): Starts user space services (PID 1).

2. Systemd (Service Management)

Most modern Linux systems use systemd to manage background services (daemons).

  • systemctl start nginx: Start a service.
  • systemctl enable nginx: Enable service to start at boot.
  • systemctl status nginx: Check if service is running or failed.
  • journalctl -u nginx: View logs specifically for that service.

3. Monitoring & Troubleshooting

  • top / htop: Real-time CPU and Memory usage.
  • df -h: Disk space usage.
  • du -sh directory/: Disk usage of a specific folder.
  • free -m: Memory usage (RAM).
  • ps aux | grep java: Find specific running processes.
  • kill -9 <PID>: Force kill a process.

Part 6: Shell Scripting (Bash)

Automation is the heart of DevOps.

Basic Bash Script Structure:

#!/bin/bash
# The shebang above tells the system to use bash

# Variables
NAME="DevOps Engineer"
DIR="/var/www/html"

# Conditionals
if [ -d "$DIR" ]; then
  echo "Directory exists."
else
  mkdir -p "$DIR"
  echo "Directory created."
fi

# Loops
for i in {1..5}; do
  echo "Iteration $i"
done

Enter fullscreen mode Exit fullscreen mode

Key Concepts:

  • Exit Status: $? (0 means success, non-zero means error).
  • Arguments: $1, $2 (First and second command line argument).
  • Redirection: > (overwrite), >> (append), | (pipe output to next command).

Part 7: SSH Configuration & Security

Secure Shell (SSH) is the primary way to manage remote Linux servers.

Configuration File: /etc/ssh/sshd_config

Security Best Practices (Hardening):

  1. Disable Root Login:
  2. Find PermitRootLogin and change to no.

  3. Disable Password Authentication (Use Keys only):

  4. Find PasswordAuthentication and change to no.

  5. Change Default Port (Optional):

  6. Change Port 22 to something like Port 2022.

Setting up Key-Based Auth:

  1. Local: Generate key: ssh-keygen -t rsa -b 4096
  2. Local: Copy to server: ssh-copy-id user@remote-server
  3. Server: Ensure permissions on ~/.ssh are 700 and ~/.ssh/authorized_keys are 600.

Part 8: Advanced Concepts & Cloud

1. Web Server Administration

  • Nginx/Apache: Used as reverse proxies or load balancers.
  • Config locations: Usually /etc/nginx/sites-available or /etc/httpd/conf/httpd.conf.
  • Log analysis: Reading access logs (/var/log/nginx/access.log) to debug 404/500 errors.

2. Linux in the Cloud (AWS/Azure/GCP)

  • Cloud-Init: A script that runs once when a cloud instance boots to install packages and write files.
  • Ephemeral Storage: Understanding that some cloud disks disappear on termination.
  • Metadata Services: Querying http://169.254.169.254 to get instance info (IP, region, etc.) from within the VM.

3. Text Processing (The "Swiss Army Knives")

DevOps engineers frequently parse logs using these:

  • grep "error" file.log: Search for text.
  • awk '{print $1}' file.txt: Print specific columns.
  • sed 's/old/new/g' file.txt: Find and replace text.

Next Step

Checkout this for advanced study on Linux for DevOps

Top comments (0)