DevOps Linux Fundamentals
Linux is the operating system that powers most servers, cloud platforms, and DevOps tools in the world. Whether deploying on AWS, running Docker containers, or configuring a Jenkins server — Linux knowledge is essential. Understanding the Linux command line makes every DevOps task faster and more precise.
Why Linux for DevOps?
- Most cloud servers (AWS EC2, Azure VM, GCP) run Linux by default.
- Docker containers are Linux-based at their core.
- DevOps tools like Jenkins, Ansible, Kubernetes, and Terraform run natively on Linux.
- Linux is open-source, stable, and highly customizable.
- Shell scripting on Linux automates repetitive DevOps tasks with ease.
Linux File System Structure
Linux organizes everything under a single root directory called /. Key directories:
| Directory | Purpose |
|---|---|
| / | Root of the entire file system |
| /home | User home directories (e.g., /home/john) |
| /etc | Configuration files for the system and services |
| /var | Log files, temporary data, databases |
| /bin | Essential commands (ls, cp, mv, etc.) |
| /usr | User-installed applications and utilities |
| /tmp | Temporary files cleared on reboot |
| /opt | Optional third-party software installations |
Essential Linux Commands
Navigation Commands
# Show current directory
pwd
# List files and folders
ls
ls -la # Shows hidden files with details
# Change directory
cd /var/log
cd .. # Go one level up
cd ~ # Go to home directoryFile and Directory Operations
# Create a directory
mkdir myapp
# Create an empty file
touch config.txt
# Copy a file
cp config.txt /tmp/config-backup.txt
# Move or rename a file
mv config.txt settings.txt
# Remove a file
rm settings.txt
# Remove a directory and all contents
rm -rf myapp/Viewing File Contents
# Print full file content
cat app.log
# View large files page by page
less app.log
# Show first 10 lines
head app.log
# Show last 10 lines (very useful for logs)
tail app.log
# Follow a log file in real time
tail -f /var/log/syslogSearching and Filtering
# Search for text inside a file
grep "ERROR" app.log
# Search recursively in all files inside a folder
grep -r "database" /etc/myapp/
# Find files by name
find /var/log -name "*.log"File Permissions in Linux
Every file in Linux has permissions that control who can read, write, or execute it. The permission string looks like this:
-rwxr-xr--Breaking it down:
- The first character:
-means file,dmeans directory. - Next three characters (
rwx): Owner permissions — read, write, execute. - Next three (
r-x): Group permissions — read, no write, execute. - Last three (
r--): Others — read only.
Changing Permissions
# Give execute permission to the owner
chmod u+x deploy.sh
# Set full permissions using numbers (7=rwx, 5=r-x, 4=r--)
chmod 755 deploy.sh
# Change file owner
chown john:devteam deploy.shUser and Process Management
User Commands
# Check current user
whoami
# Switch user
su - john
# Run a command as administrator
sudo apt updateProcess Commands
# View running processes
ps aux
# Live system resource monitor
top
# Kill a process by ID
kill 1234
# Kill by process name
pkill nginxPackage Management
Installing software on Linux uses a package manager. Two common ones:
APT (Ubuntu/Debian)
# Update package list
sudo apt update
# Install a package
sudo apt install nginx
# Remove a package
sudo apt remove nginxYUM / DNF (CentOS/RHEL/Amazon Linux)
# Install a package
sudo yum install nginx
# Update all packages
sudo yum updateNetworking Commands
# Check IP address
ip addr show
# Test connectivity to a host
ping google.com
# Check open ports
netstat -tuln
# Make an HTTP request
curl https://api.example.com/status
# Download a file
wget https://example.com/setup.shShell Scripting Basics
Shell scripts automate sequences of Linux commands. A script is a plain text file that runs line by line.
Simple Deployment Script Example
#!/bin/bash
# This script deploys a web app
echo "Starting deployment..."
# Pull latest code
cd /var/www/myapp
git pull origin main
# Restart the web server
sudo systemctl restart nginx
echo "Deployment complete!"Save this as deploy.sh, make it executable with chmod +x deploy.sh, then run it with ./deploy.sh.
systemctl – Managing Services
Linux services (like web servers and databases) are managed with systemctl:
# Start a service
sudo systemctl start nginx
# Stop a service
sudo systemctl stop nginx
# Restart a service
sudo systemctl restart nginx
# Check service status
sudo systemctl status nginx
# Enable a service to start on boot
sudo systemctl enable nginxViewing Logs
Logs are critical in DevOps for troubleshooting deployments and monitoring applications.
# View system journal logs
journalctl -u nginx
# Follow live journal logs
journalctl -fu nginx
# View application log
cat /var/log/myapp/error.logSSH – Remote Access
SSH (Secure Shell) connects to remote Linux servers securely. In DevOps, SSH is used to manage cloud servers.
# Connect to a remote server
ssh john@192.168.1.100
# Connect using a key file (common for AWS EC2)
ssh -i mykey.pem ubuntu@54.10.20.30
# Copy a file to a remote server
scp deploy.sh john@192.168.1.100:/home/john/Real-World Example
A DevOps engineer needs to deploy a new version of a Node.js app on a Linux server:
- SSH into the server:
ssh -i mykey.pem ubuntu@54.200.100.50 - Navigate to the app folder:
cd /var/www/nodeapp - Pull latest code:
git pull origin main - Restart the app service:
sudo systemctl restart nodeapp - Check status:
sudo systemctl status nodeapp - Tail logs to confirm it's working:
tail -f /var/log/nodeapp/app.log
Summary
- Linux is the backbone of almost every DevOps environment.
- Key skills include file navigation, permissions, process management, and package installation.
- Shell scripting automates repetitive deployment and maintenance tasks.
- SSH provides secure remote access to servers for hands-on management.
- Log viewing and systemctl are daily tools for monitoring and managing services.
