Linux For DevOps: Basics to Advanced

LINUX For DevOPS

This article covers the essential Linux basics every beginner and DevOps learner should know. From understanding the OS and Linux distributions to navigating the file system, managing users and permissions, analyzing logs with tools like grep and awk, and setting up SSH with key-based authentication, you’ll get a solid foundation to start working confidently in Linux environments.

Table of Contents

1. What is an Operating System?

An Operating System (OS) is a fundamental software layer that acts as an interface between computer hardware and the user. It manages all hardware components—such as CPU, memory, storage devices, and input/output peripherals and coordinates the execution of software applications. Without an operating system, a computer would be practically unusable, as users and applications would not be able to communicate effectively with the hardware.

Popular operating systems include:

  • Linux
  • macOS
  • Windows

Why is Linux preferred in DevOps?

In DevOps, Linux is the operating system of choice due to its stability, security, and flexibility. It provides a reliable environment where systems can run for extended periods without interruption, which is crucial for continuous deployment and high-availability services. Linux’s strong security model, frequent updates, and open-source nature make it a trusted platform for managing production workloads, reducing the risk of vulnerabilities, and ensuring system integrity.

Another reason Linux dominates DevOps is its compatibility with most modern DevOps tools like Docker, Kubernetes, Jenkins, and Ansible. These tools are often designed to run natively on Linux, making integration and automation seamless. Additionally, Linux is free and open-source, allowing organizations to scale infrastructure without costly licensing fees.

2. Client OS vs Server OS

Client OS

A Client Operating System is designed for end-users to perform everyday tasks like browsing the internet, using office applications, and playing multimedia.

Examples: Windows 11, Ubuntu Desktop, macOS

Server OS

A Server Operating System, on the other hand, is built to manage network resources, run web servers, databases, and support multiple users simultaneously. It offers advanced security, stability, and remote management features.

Examples: Red Hat Enterprise Linux, Ubuntu Server, Amazon Linux

3. Why Linux for DevOps?

Linux is the most widely used operating system in DevOps due to its open-source nature, high stability, strong security, and powerful command-line interface. It provides an ideal environment for automation, scripting, containerization, and infrastructure management, making it the go-to choice for DevOps engineers and teams.

Key Reasons Why Linux is Preferred in DevOps:
  • Open-source and Free: No licensing costs; highly customizable for different environments.
  • Tool Compatibility: Most DevOps tools, like Docker, Kubernetes, Jenkins, and Ansible are built to run on Linux.
  • Scriptable and Automatable: Bash scripting and cron jobs make automation simple and efficient.
  • Stability and Performance: Can run for months or years without needing a reboot.
  • Security: Strong user permission system and regular community-driven updates and patches.
  • Cloud and Container Support: Linux is the default OS in most cloud platforms and container ecosystems.

Fact: Created by Linus Torvalds, inspired by Unix

4. Ways to Set Up Linux

1. Install on Your System (Bare Metal Installation)
This method involves installing a Linux distribution (like Ubuntu, Fedora, or CentOS) directly onto your computer's hard drive. It can be set up as a standalone OS or as a dual-boot alongside Windows. Ideal for full performance and long-term use.

2. EC2 Instance on AWS
Amazon EC2 lets you launch Linux virtual machines (instances) in the cloud. It’s widely used for deploying web applications, running DevOps pipelines, or learning Linux without needing local resources. AWS offers many Linux-based AMIs like Ubuntu, Amazon Linux, and Red Hat.

3. VirtualBox + ISO File
Use virtualization software like VirtualBox to create a virtual machine and run Linux using an ISO image. This is perfect for testing, learning, or running Linux without modifying your existing system.

4. Docker Container
Docker allows you to run lightweight, isolated Linux environments called containers. It's widely used in DevOps for creating consistent development and production environments. Great for testing, automation, and microservices.

5. Windows Subsystem for Linux (WSL)
WSL enables you to run a Linux terminal and command-line tools directly on Windows without a virtual machine. WSL 2 even supports full Linux kernels and Docker integration. Best for developers who want Linux tools on a Windows machine.

5. Linux Architecture (ASK Model)

The Linux architecture can be understood using the ASK model, which stands for Application, Shell, and Kernel. This layered structure defines how Linux operates and interacts with users and hardware.

  • Application Layer
    This is the top layer where user-level software runs. Applications like Vim, Git, Python, and text editors operate here. These tools help users perform development, editing, or version control tasks.

  • Shell Layer
    The Shell acts as a command-line interface (CLI) between the user and the system. Tools like Bash, Zsh, or Fish accept user commands and translate them into instructions that the kernel can understand.

  • Kernel Layer
    The Kernel is the core of the Linux OS. It directly interacts with the hardware, manages system resources (CPU, memory, devices), and ensures secure and efficient operation. It acts as a bridge between the Shell and the hardware.


 

 

6. Shell & Shell Scripting

Shell is a command-line interface that allows users to interact with the operating system by typing commands. In Linux, common shells include Bash, Zsh, and Sh.

Shell Scripting is the process of writing a series of shell commands in a file (usually with .sh extension) to automate repetitive tasks like file operations, system monitoring, software installation, and more.

In short, Shell executes commands, and Shell Scripting automates them

Types of Shells: Bash, Csh, Zsh

7. Basic Linux Commands

CommandDescriptionExample
pwdShow current directorypwd
cdChange directorycd /var/log
mkdirCreate directorymkdir project
touchCreate filetouch log.txt
catView filecat file.txt
ls -aShow hidden filesls -a
rmDelete filerm file.txt

8. Important Directories

DirectoryPurpose
/homeUser-specific data
/varLogs, mail, cache
/binBasic commands (ls, cp)
/sbinSystem commands (reboot)
/rootRoot user home

9. man Command

man ls
man grep

10. APT Package Manager (Ubuntu)

sudo apt update
sudo apt upgrade
sudo apt install nginx

Use sudo to run admin-level commands.

cat /etc/group

11. systemctl for Services

sudo apt install nginx
systemctl status nginx
systemctl start nginx
systemctl restart nginx
DevOps Scenario:
You deployed a Node.js app using NGINX. After deployment, NGINX doesn’t respond.
Use: systemctl status nginx to debug.

19. User and Group Management

In a real DevOps setup, managing users and groups is crucial for security, access control, and automation.

Create a New User

sudo adduser devuser

This creates a new user named devuser with a home directory.

Give Sudo (Admin) Access

sudo usermod -aG sudo devuser

This adds devuser to the sudo group, giving them admin privileges.

Create a New Group

sudo groupadd devgroup

This creates a custom group called devgroup, useful for permission control across multiple users.

Add User to Group

sudo usermod -aG devgroup devuser

This adds devuser to devgroup. Great for grouping similar DevOps engineers, QA testers, or backend devs.

Check User Groups

groups devuser

This shows which groups a user belongs to.

Why It Matters in DevOps: When deploying applications, securing servers, or configuring automation tools like Ansible, you must manage who can read/write/execute or access critical paths. Groups help restrict or expand access cleanly.

13. Understanding File Permissions in Linux

Linux uses a permission system to manage access to files and directories. These permissions are split into three categories:

  • User (u) – The owner of the file
  • Group (g) – Users in the same group
  • Other (o) – Everyone else

Each category has three types of permissions:

  • r = read
  • w = write
  • x = execute

These permissions are represented by binary values:

rwxBinaryDecimal
0000000
0010011
0100102
0110113
1001004
1011015
1101106
1111117

So a file permission like chmod 754 file.txt means:

  • User: 7 (rwx)
  • Group: 5 (r-x)
  • Other: 4 (r--)

You can check file permissions using:

ls -l file.txt

And change them using:

chmod 755 script.sh

This gives full access to the user, and read-execute access to group and others.

14. Log File Analysis for DevOps (AWK, GREP, SED)

As a DevOps engineer, analyzing logs is a daily task. Tools like grep, awk, and sed are your best friends for troubleshooting, monitoring, and automating tasks.

Sample Log File: auth.log

Jul 02 12:10:11 server1 sshd[2345]: Failed password for invalid user admin from 192.168.1.12 port 55874 ssh2
Jul 02 12:12:33 server1 sshd[2346]: Accepted password for devuser from 192.168.1.15 port 55233 ssh2
Jul 02 12:15:44 server1 sshd[2347]: Failed password for root from 192.168.1.10 port 54421 ssh2

GREP - Search within logs

grep "Failed password" auth.log

Use case: Find all failed login attempts. You can also count how many:

grep -c "Failed password" auth.log

AWK - Extract specific fields

awk '{print $1, $2, $3, $9, $11}' auth.log

Use case: Extract Date, Time, and Username from login entries.

Output: Jul 02 12:10:11 admin

SED - Replace or clean logs

sed 's/Failed password/LOGIN FAIL/g' auth.log

Use case: Replace all "Failed password" texts to make logs more readable.

Sample Log File: nginx.log

192.168.1.11 - - [02/Jul/2025:13:15:01 +0000] "GET /index.html HTTP/1.1" 200 1024
192.168.1.12 - - [02/Jul/2025:13:16:02 +0000] "POST /login HTTP/1.1" 403 512
192.168.1.15 - - [02/Jul/2025:13:16:35 +0000] "GET /dashboard HTTP/1.1" 500 2560

Find status codes with GREP

grep " 403 " nginx.log

Use case: Find all forbidden access attempts.

AWK - Extract IP and status

awk '{print $1, $9}' nginx.log

Use case: Extract client IP and response status code.

SED - Clean logs by removing status codes

sed 's/ [0-9]\{3\} [0-9]\+/ - -/g' nginx.log

Use case: Anonymize response codes for sharing logs externally.

Recommended Resources

Pro Tip: Combine grep with awk or sed using pipes for powerful one-liners.

grep "Failed" auth.log | awk '{print $NF}'

This gives you only the IPs involved in failed login attempts.

15. Basic Networking Commands

ip a
ping google.com
traceroute google.com
netstat -tulnp
ss -tulnp

16. SSH and Key-based Authentication

ssh-keygen -t rsa -b 2048
ssh-copy-id user@remote_ip
ssh -i ~/.ssh/id_rsa user@remote_ip

Scenario: Your DevOps team deploys code to staging servers daily. Instead of typing passwords each time, use key-based SSH for seamless, secure connections.

Challenge Yourself

  • Create a user named deployadmin and give it sudo access.
  • Write a shell script to monitor disk space usage.
  • Use grep to find “error” logs in a log file.
  • Set up SSH access to a dummy EC2 instance on AWS.

👉 Connect with me on LinkedIn for more DevOps insights

About the Author

Written by Omkar Goswami, a passionate DevOps engineer sharing real-world knowledge. For suggestions or feedback, connect on LinkedIn.

Conclusion

Linux is the backbone of DevOps. From system navigation to user management, from processing log files to securing servers with SSH, mastering Linux boosts your effectiveness as a DevOps engineer. Practice these commands regularly and start building real-world projects.

Stay tuned: Next article will cover \"Linux for DevOps - Shell Scripting in Real-World Projects\".

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS