Linux Basics & Scripting for a DevOps Engineer
Introduction
Linux is the backbone of modern DevOps practices, powering cloud servers, containers, and automation frameworks. As a DevOps engineer, mastering Linux and scripting is crucial for system administration, automation, and managing infrastructure efficiently. This guide covers essential Linux basics and scripting concepts to help you excel in your DevOps journey.
Why Linux is Essential for DevOps
Linux is widely used in DevOps due to its:
- Open-source nature – Free and customizable.
- Stability & Security – Reliable for production environments.
- Command-line interface (CLI) power – Efficient system management.
- Compatibility with DevOps tools – Works with Docker, Kubernetes, Ansible, Terraform, and more.
- Support for automation & scripting – Enables Infrastructure as Code (IaC).
Linux Fundamentals
1. Understanding Linux File System
Linux follows a hierarchical file system structure:
/
– Root directory/home/
– User home directories/etc/
– System configuration files/var/
– Logs and variable data/bin/
&/usr/bin/
– Executable binaries/tmp/
– Temporary files
2. Basic Linux Commands
File and Directory Operations
$ ls -l # List files with details
$ cd /path # Change directory
$ touch file # Create a new file
$ mkdir dir # Create a new directory
$ rm file # Remove a file
$ rm -r dir # Remove a directory recursively
User and Permission Management
$ whoami # Show current user
$ id user # Display user details
$ chmod 755 file # Change file permissions
$ chown user:group file # Change file ownership
Lists all groups a user belongs to.
$ groups username
Provides detailed user information, including login details and home directory.
$ finger username
Retrieves user information from the system's database, such as /etc/passwd
.
$ getent passwd username
Searches for a specific username in system files, such as the user database.
$ grep username /etc/passwd
Displays information about user accounts, including login statistics.
lslogins -u
Lists all currently logged-in users.
$ users
Shows details of users currently logged into the system.
$ who -u
Displays active users along with their login time, terminal, and system activity.
$ w
Shows recent login sessions, including user login times and terminals.
View all recent logins:
$ last
View currently logged-in users:
$ last -ap now
Displays a list of failed login attempts.
$ lastb
Lists the last login details of all users or a specific user.
View login history for all users:
$ lastlog
View login history for a specific user:
$ lastlog -u username
Process and System Monitoring
$ ps aux # View running processes
$ top # Monitor system usage
$ kill PID # Terminate a process
$ free -m # Check memory usage
$ df -h # Check disk space
3. Package Management
- Debian-based (Ubuntu, Debian):
$ apt update && apt upgrade # Update system $ apt install package # Install a package $ apt remove package # Remove a package
- RHEL-based (CentOS, Fedora, RHEL):
$ yum install package # Install a package $ yum remove package # Remove a package
Shell Scripting for Automation
Shell scripting helps automate repetitive tasks, making DevOps processes more efficient.
1. Writing a Basic Shell Script
#!/bin/bash
echo "Hello, DevOps Engineer!"
Steps to Run:
chmod +x script.sh # Make executable
./script.sh # Execute script
2. Variables in Shell Scripting
#!/bin/bash
name="DevOps Engineer"
echo "Welcome, $name!"
3. Conditional Statements
#!/bin/bash
if [ -f /etc/passwd ]; then
echo "User database exists."
else
echo "User database missing."
fi
4. Loops in Shell Scripts
For Loop:
#!/bin/bash
for i in 1 2 3 4 5
do
echo "Number: $i"
done
While Loop:
#!/bin/bash
count=1
while [ $count -le 5 ]
do
echo "Count: $count"
((count++))
done
5. Functions in Shell Scripting
#!/bin/bash
greet() {
echo "Hello, $1!"
}
greet "DevOps Engineer"
Advanced Linux Topics for DevOps
1. Process Automation with Cron Jobs
Automate tasks using cron jobs:
$ crontab -e
Example entry to run a script every day at midnight:
0 0 * * * /path/to/script.sh
2. Log Management with Linux Commands
- View logs:
tail -f /var/log/syslog
- Search logs:
grep "error" /var/log/syslog
3. Networking Commands for DevOps
- Check IP address:
ip a
- Test network connectivity:
ping google.com
- Open ports & listening services:
netstat -tulnp
4. Infrastructure Automation with Bash & Cloud CLI
- AWS CLI example:
$ aws s3 ls # List S3 buckets
- Terraform example:
$ terraform init && terraform apply
Conclusion
Linux is a core skill for any DevOps engineer. Mastering command-line operations, scripting, automation, and system management helps you build efficient and scalable infrastructures. By combining Linux with cloud computing, containerization, and DevOps tools, you can accelerate your DevOps career.
Are you ready to level up your DevOps skills? Start practicing Linux commands and automate your first script today! 🚀
🚀 Kickstart Your DevOps Career with Expert Guidance! 🚀
Want to break into DevOps but not sure where to start? Or looking to level up your skills in CI/CD, Kubernetes, Terraform, Cloud, and DevSecOps?
📢 Book a 1:1 session with Shyam Mohan K and get:
✅ A personalized DevOps roadmap tailored to your experience
✅ Hands-on guidance on real-world DevOps tools
✅ Tips on landing a DevOps job and interview preparation
📅 Book your session today! 👉 https://calendly.com/kubeify/
#DevOps #CloudComputing #CICD #Kubernetes #AWS #Terraform #TechCareer #CareerGrowth #Learning #ITJobs
Comments
Post a Comment