Linux For DevOps: Basics to Advanced

LINUX For DevOPS

Quick Summary

  • Basics of OS, Linux Distributions
  • File system navigation & commands
  • User, Group, and Permission Management
  • Real-world log analysis with grep, awk, sed
  • Networking and SSH with key-based auth

Table of Contents

1. What is an Operating System?

An Operating System (OS) is software that manages computer hardware and software resources. It allows users and applications to interact with the hardware.

Examples: Linux, macOS, Windows

In the DevOps world, Linux is most commonly used because it is stable, secure, and cost-effective.

2. Client OS vs Server OS

Client OS

Used for personal tasks like browsing, watching videos, and coding.

Examples: Windows 11, Ubuntu Desktop

Server OS

Used to host services and applications.

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

3. Why Linux for DevOps?

  • Open-source and free
  • Secure and stable
  • Huge community support
  • No antivirus required
  • Multiple distributions (Ubuntu, RHEL, CentOS, etc.)

Fact: Created by Linus Torvalds, inspired by Unix

4. Ways to Set Up Linux

  1. Install on your system
  2. EC2 instance on AWS
  3. VirtualBox + ISO
  4. Docker container
  5. Windows Subsystem for Linux (WSL)

5. Linux Architecture (ASK Model)

  • Application: Tools like vim, git, python
  • Shell: Command-line interface (e.g., bash)
  • Kernel: Core layer interacting with hardware

 

 


 

 

6. Shell & Shell Scripting

Typing commands is good, but saving a set of commands in a .sh file makes it reusable.

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