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 likels,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 forifconfig). -
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 -tulpnorss -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/tcpfirewall-cmd --reloadiptables: The legacy, low-level tool for table-based packet filtering.
Part 5: Processes, Systemd, and Boot
1. The Boot Process
- BIOS/UEFI: Hardware check, loads bootloader.
- Bootloader (GRUB): Loads the Kernel.
-
Kernel: Mounts root filesystem, starts
init. - 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
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):
- Disable Root Login:
Find
PermitRootLoginand change tono.Disable Password Authentication (Use Keys only):
Find
PasswordAuthenticationand change tono.Change Default Port (Optional):
Change
Port 22to something likePort 2022.
Setting up Key-Based Auth:
-
Local: Generate key:
ssh-keygen -t rsa -b 4096 -
Local: Copy to server:
ssh-copy-id user@remote-server -
Server: Ensure permissions on
~/.sshare 700 and~/.ssh/authorized_keysare 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-availableor/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.254to 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)