Table of Contents
- 1. What is an Operating System?
- 2. Client vs Server OS
- 3. Why Linux for DevOps?
- 4. Ways to Set Up Linux
- 5. Linux Architecture (ASK Model)
- 6. Shell & Shell Scripting
- 7. Basic Linux Commands
- 8. Important Directories
- 9. man Command
- 10. APT Package Manager
- 11. systemctl for Services
- 12. User and Group Management
- 13. File Permissions
- 14. Day-to-Day Commands with Real Example
- 15. Networking Commands
- 16. SSH and Key-based Authentication
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?
- 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
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
Command | Description | Example |
---|---|---|
pwd | Show current directory | pwd |
cd | Change directory | cd /var/log |
mkdir | Create directory | mkdir project |
touch | Create file | touch log.txt |
cat | View file | cat file.txt |
ls -a | Show hidden files | ls -a |
rm | Delete file | rm file.txt |
8. Important Directories
Directory | Purpose |
---|---|
/home | User-specific data |
/var | Logs, mail, cache |
/bin | Basic commands (ls, cp) |
/sbin | System commands (reboot) |
/root | Root 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
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
= readw
= writex
= execute
These permissions are represented by binary values:
r | w | x | Binary | Decimal |
---|---|---|---|---|
0 | 0 | 0 | 000 | 0 |
0 | 0 | 1 | 001 | 1 |
0 | 1 | 0 | 010 | 2 |
0 | 1 | 1 | 011 | 3 |
1 | 0 | 0 | 100 | 4 |
1 | 0 | 1 | 101 | 5 |
1 | 1 | 0 | 110 | 6 |
1 | 1 | 1 | 111 | 7 |
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: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.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\".
No comments:
Post a Comment