Skip to main content

Linux Interview & DevOps Scenarios

 

Linux Interview/Practical Scenarios: Real-World DevOps Challenges

Prepare for Linux interviews with hands-on scenarios that DevOps engineers face daily

📅 Published: Feb 2026
⏱️ Estimated Reading Time: 15 minutes
🏷️ Tags: Linux Commands, DevOps Interviews, System Administration, Troubleshooting


Overview

Linux skills are non-negotiable for DevOps roles. While knowing commands is good, solving real problems is what gets you hired.

This guide presents practical scenarios that you'll encounter in DevOps interviews and daily work, with step-by-step solutions and explanations.


Real-world Use Cases for DevOps

1. Server Health Check & Monitoring

Scenario: You join a new team and need to assess server health immediately.

What to Check:

bash
# Check overall system health
top                  # Real-time process monitoring
htop                 # Better visual alternative
uptime              # System load averages
free -h             # Memory usage (human readable)
df -h               # Disk space (human readable)

# Check running services
systemctl list-units --type=service --state=running

# Check for high CPU processes
ps aux --sort=-%cpu | head -10

# Check for high memory processes
ps aux --sort=-%mem | head -10

DevOps Context: Daily health checks, alert setup, capacity planning.


2. Log Analysis & Troubleshooting

Scenario: Application is slow. You need to find why.

Approach:

bash
# 1. Check application logs
tail -100 /var/log/application.log

# 2. Search for errors
grep -i "error\|exception\|fail" /var/log/application.log

# 3. Monitor real-time logs
tail -f /var/log/application.log

# 4. Check system logs
journalctl -xe --since "10 minutes ago"

# 5. Analyze slow requests (if web server)
tail -100 /var/log/nginx/access.log | awk '{print $1, $4, $7, $9}' | sort | uniq -c | sort -rn

DevOps Context: Debugging production issues, performance optimization.


3. Disk Space Emergency

Scenario: Server alerts: Disk is 95% full. Application failing.

Immediate Actions:

bash
# 1. Find what's consuming space
du -sh /* 2>/dev/null | sort -rh | head -10

# 2. Find large files (>100MB)
find / -type f -size +100M 2>/dev/null | head -20

# 3. Check log rotation status
ls -lh /var/log/*.log

# 4. Clean old logs (safely)
find /var/log -name "*.log" -type f -mtime +30 -delete

# 5. Check Docker disk usage
docker system df

# 6. Clear Docker cache
docker system prune -a

DevOps Context: Storage management, cleanup automation, monitoring setup.


4. Network Connectivity Issues

Scenario: Server can't connect to database. Need to diagnose.

Troubleshooting Steps:

bash
# 1. Check basic connectivity
ping database-hostname

# 2. Check DNS resolution
nslookup database-hostname
dig database-hostname

# 3. Check port connectivity
telnet database-hostname 3306
# OR
nc -zv database-hostname 3306

# 4. Check firewall rules
iptables -L -n -v
# OR for newer systems
firewall-cmd --list-all

# 5. Check network routes
traceroute database-hostname

# 6. Check if service is listening
netstat -tulpn | grep :3306
# OR
ss -tulpn | grep :3306

DevOps Context: Network debugging, connectivity automation, firewall management.


Linux Interview Questions with Practical Answers

Q1: How do you find all files containing a specific string?

Practical Answer:

bash
# Recursive search in current directory
grep -r "specific-string" .

# Case-insensitive search
grep -ri "specific-string" .

# Show line numbers
grep -rn "specific-string" .

# Search only in certain file types
grep -r "specific-string" --include="*.conf" .

# Real use case: Find where API key is used
grep -r "API_KEY_" /opt/app/

Q2: How to find which process is using a specific port?

Practical Answer:

bash
# Method 1: Using lsof
lsof -i :8080

# Method 2: Using netstat
netstat -tulpn | grep :8080

# Method 3: Using ss (modern alternative)
ss -tulpn | grep :8080

# Method 4: Find by port number
fuser 8080/tcp

# Real use case: Port 8080 is already in use by unknown process
# Solution: Kill the process if needed
kill -9 $(lsof -t -i:8080)

Q3: How to monitor real-time system resources?

Practical Answer:

bash
# 1. CPU and Memory - Basic
top

# 2. Better visualization
htop

# 3. Disk I/O monitoring
iotop

# 4. Network traffic
iftop

# 5. Custom monitoring script
while true; do
    echo "--- $(date) ---"
    echo "CPU Load: $(uptime)"
    echo "Memory: $(free -h | awk '/^Mem:/{print $3"/"$2}')"
    echo "Disk: $(df -h / | awk 'NR==2{print $3"/"$2}')"
    sleep 5
done

Q4: How to schedule a job to run daily?

Practical Answer:

bash
# Using cron (most common)
# Edit crontab
crontab -e

# Examples:
# Run backup daily at 2 AM
0 2 * * * /opt/scripts/backup.sh

# Run cleanup every Sunday at 3 AM
0 3 * * 0 /opt/scripts/cleanup.sh

# Run every 5 minutes (monitoring)
*/5 * * * * /opt/scripts/monitor.sh

# Run on first day of month
0 0 1 * * /opt/scripts/monthly-report.sh

# Check cron logs
tail -f /var/log/cron

Q5: How to securely copy files between servers?

Practical Answer:

bash
# Basic SCP (secure copy)
scp file.txt user@remote-server:/path/

# Copy directory recursively
scp -r /local/dir user@remote-server:/remote/dir/

# Preserve permissions and timestamps
scp -p file.txt user@remote-server:/path/

# Using rsync (better for large files/sync)
rsync -avz /local/path/ user@remote-server:/remote/path/

# Using rsync with SSH key
rsync -avz -e "ssh -i ~/.ssh/key.pem" file.txt user@server:/path/

# Real DevOps use: Deploy application
rsync -avz --delete build/ deploy-user@prod-server:/var/www/app/

Troubleshooting Scenarios

Scenario 1: Server Suddenly Slow

Symptoms: High load average, slow response time.

Investigation:

bash
# 1. Check load average
uptime
# Output: 12:00:00 up 30 days, load average: 4.50, 3.20, 2.80
# Rule: Load > CPU cores = Problem

# 2. Identify top CPU consumers
ps aux --sort=-%cpu | head -5

# 3. Check memory usage
free -h

# 4. Check disk I/O (if high, could be swapping)
iostat -dx 2

# 5. Check swap usage
swapon --show
free -h | grep -i swap

# 6. Check for zombie processes
ps aux | grep 'Z'

# Common causes:
# - Memory leak → Process using all RAM
# - Disk full → Cannot write logs
# - Too many connections → Network bottleneck

Scenario 2: Can't SSH to Server

Symptoms: Connection timeout, permission denied.

Debug Steps:

bash
# From your machine, test:
ssh -v user@server  # Verbose output

# If connection timeout:
# 1. Check if server is up
ping server-ip

# 2. Check if SSH port is open
telnet server-ip 22

# 3. Check firewall (if you have access to another port)
# If web server works (port 80) but SSH doesn't → Firewall blocking

# If permission denied:
# 1. Check SSH key permissions
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub

# 2. Check server SSH config (if you can access via console)
sudo tail -f /var/log/auth.log

# 3. Common fix: Restart SSH service
sudo systemctl restart sshd

Scenario 3: Application Logs Missing

Symptoms: Application crashing, no error logs.

Investigation:

bash
# 1. Check if application is running
ps aux | grep application-name

# 2. Check process output
sudo journalctl -u application-service

# 3. Check system logs
sudo tail -f /var/log/syslog

# 4. Check if disk is full (logs can't write)
df -h

# 5. Check logrotate configuration
ls -la /etc/logrotate.d/

# 6. Manually test logging
echo "Test log" | sudo tee -a /var/log/application.log

# 7. Check permissions
ls -la /var/log/application.log

Scenario 4: Database Connection Failures

Symptoms: Application can't connect to database.

Debug Commands:

bash
# 1. Check if database is running
sudo systemctl status mysql  # or postgresql/mongodb

# 2. Check database logs
sudo tail -f /var/log/mysql/error.log

# 3. Test database connection locally
mysql -u username -p -h localhost

# 4. Check if port is listening
sudo netstat -tulpn | grep :3306

# 5. Check database configuration
sudo cat /etc/mysql/mysql.conf.d/mysqld.cnf | grep bind-address
# Should be: bind-address = 0.0.0.0 (for remote) or 127.0.0.1 (local only)

# 6. Check firewall rules
sudo ufw status
# Allow MySQL port: sudo ufw allow 3306

Hands-on Practice Tasks

Task 1: Create a System Monitoring Script

Objective: Write a script that monitors system health and sends alerts.

Solution:

bash
#!/bin/bash
# save as: /opt/scripts/monitor.sh

THRESHOLD_CPU=80
THRESHOLD_MEM=90
THRESHOLD_DISK=85

# Get current usage
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1)
MEM_USAGE=$(free | awk '/Mem/{printf("%.0f"), $3/$2*100}')
DISK_USAGE=$(df / | awk 'NR==2{print $5}' | sed 's/%//')

# Check thresholds
if [ $CPU_USAGE -gt $THRESHOLD_CPU ]; then
    echo "ALERT: High CPU usage: ${CPU_USAGE}%" | mail -s "CPU Alert" admin@example.com
fi

if [ $MEM_USAGE -gt $THRESHOLD_MEM ]; then
    echo "ALERT: High Memory usage: ${MEM_USAGE}%" | mail -s "Memory Alert" admin@example.com
fi

if [ $DISK_USAGE -gt $THRESHOLD_DISK ]; then
    echo "ALERT: High Disk usage: ${DISK_USAGE}%" | mail -s "Disk Alert" admin@example.com
fi

# Log to file
echo "$(date) - CPU:${CPU_USAGE}% MEM:${MEM_USAGE}% DISK:${DISK_USAGE}%" >> /var/log/system-monitor.log

Task 2: Automate Log Cleanup

Objective: Create a script that archives old logs and cleans disk.

Solution:

bash
#!/bin/bash
# save as: /opt/scripts/log-cleanup.sh

LOG_DIR="/var/log"
BACKUP_DIR="/backup/logs"
RETENTION_DAYS=30

# Create backup directory if not exists
mkdir -p $BACKUP_DIR

# Archive logs older than 7 days
find $LOG_DIR -name "*.log" -type f -mtime +7 | while read logfile; do
    filename=$(basename $logfile)
    tar -czf $BACKUP_DIR/${filename}.$(date +%Y%m%d).tar.gz $logfile
    echo "Archived: $logfile"
done

# Delete old backups (older than retention)
find $BACKUP_DIR -name "*.tar.gz" -type f -mtime +$RETENTION_DAYS -delete

# Clean application logs (keep last 1000 lines)
for app_log in /var/log/app/*.log; do
    tail -1000 $app_log > $app_log.tmp
    mv $app_log.tmp $app_log
done

echo "Log cleanup completed at $(date)" >> /var/log/cleanup.log

Task 3: User Management Automation

Objective: Script to add developers with proper permissions.

Solution:

bash
#!/bin/bash
# save as: /opt/scripts/add-developer.sh

if [ $# -eq 0 ]; then
    echo "Usage: $0 username [ssh-public-key]"
    exit 1
fi

USERNAME=$1
SSH_KEY=$2

# Create user with home directory
sudo useradd -m -s /bin/bash $USERNAME

# Set initial password (user will change on first login)
echo "$USERNAME:TempPass123" | sudo chpasswd
sudo chage -d 0 $USERNAME  # Force password change on first login

# Add to developers group
sudo groupadd developers 2>/dev/null
sudo usermod -aG developers $USERNAME

# Add to sudoers (with restrictions)
echo "$USERNAME ALL=(ALL) NOPASSWD: /usr/bin/systemctl, /usr/bin/docker" | sudo tee /etc/sudoers.d/$USERNAME

# Set up SSH if key provided
if [ ! -z "$SSH_KEY" ]; then
    sudo mkdir -p /home/$USERNAME/.ssh
    echo "$SSH_KEY" | sudo tee /home/$USERNAME/.ssh/authorized_keys
    sudo chmod 700 /home/$USERNAME/.ssh
    sudo chmod 600 /home/$USERNAME/.ssh/authorized_keys
    sudo chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
fi

echo "User $USERNAME created successfully"

Task 4: Docker Container Management

Objective: Script to manage Docker containers with health checks.

Solution:

bash
#!/bin/bash
# save as: /opt/scripts/docker-manager.sh

ACTION=$1
CONTAINER=$2

case $ACTION in
    start)
        docker start $CONTAINER
        ;;
    stop)
        docker stop $CONTAINER
        ;;
    restart)
        docker restart $CONTAINER
        ;;
    status)
        docker ps -a | grep $CONTAINER
        ;;
    logs)
        docker logs --tail 100 -f $CONTAINER
        ;;
    health)
        # Check if container is running
        if [ "$(docker inspect -f '{{.State.Running}}' $CONTAINER 2>/dev/null)" == "true" ]; then
            echo "Container $CONTAINER is running"
            
            # Check response from web container
            if [[ $CONTAINER == *"web"* ]]; then
                curl -f http://localhost:8080/health >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                    echo "Web service is responding"
                else
                    echo "Web service is NOT responding"
                fi
            fi
        else
            echo "Container $CONTAINER is NOT running"
        fi
        ;;
    cleanup)
        # Remove stopped containers
        docker container prune -f
        
        # Remove unused images
        docker image prune -af
        
        # Remove unused volumes
        docker volume prune -f
        
        echo "Docker cleanup completed"
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status|logs|health|cleanup} [container-name]"
        exit 1
        ;;
esac

Interview Preparation Checklist

Must-Know Commands:

bash
# Process Management
ps, top, htop, kill, pkill, nice, renice

# File Operations
find, grep, sed, awk, sort, uniq, cut, tr

# Network
netstat, ss, curl, wget, ping, traceroute, dig, nslookup

# System Info
uname, hostname, whoami, id, groups, date

# Disk & Filesystem
df, du, mount, umount, fdisk, lsblk

# Permissions
chmod, chown, chgrp, umask, getfacl, setfacl

# Package Management
apt, yum, dnf, rpm, dpkg (know your distro!)

Common Interview Questions:

  1. "How do you find a file that was modified yesterday?"

  2. "What's the difference between soft link and hard link?"

  3. "How do you check open files by a process?"

  4. "Explain load average in simple terms"

  5. "How to schedule a job that runs every weekday at 2 PM?"

  6. "What's the difference between kill and kill -9?"

  7. "How to check if a port is open on remote server?"

  8. "Explain chmod 755 in detail"

  9. "How to monitor real-time disk I/O?"

  10. "What's the purpose of /etc/fstab?"


Real DevOps Workflow Example

Deploying an Application:

bash
#!/bin/bash
# Application deployment script

# 1. Pull latest code
cd /opt/application
git pull origin main

# 2. Build application
docker build -t myapp:latest .

# 3. Stop old container
docker stop myapp-container 2>/dev/null
docker rm myapp-container 2>/dev/null

# 4. Run new container
docker run -d \
  --name myapp-container \
  --restart unless-stopped \
  -p 8080:8080 \
  -v /opt/app/config:/config \
  -e NODE_ENV=production \
  myapp:latest

# 5. Health check
sleep 10
curl -f http://localhost:8080/health || exit 1

# 6. Update load balancer (if applicable)
# aws elbv2 modify-listener ...

echo "Deployment completed successfully"

Practice Environment Setup

Using Docker for Practice:

bash
# Create a practice Linux environment
docker run -it --name linux-practice ubuntu:latest /bin/bash

# Or use Vagrant
vagrant init ubuntu/focal64
vagrant up
vagrant ssh

# Or use Multipass (Ubuntu)
multipass launch --name devops-practice
multipass shell devops-practice

Practice Projects:

  1. Set up a web server (Nginx/Apache)

  2. Configure firewall rules

  3. Set up monitoring with Prometheus

  4. Create backup automation

  5. Build a CI/CD pipeline

  6. Configure log aggregation


Summary Table: Linux DevOps Skills

Skill CategoryKey CommandsReal-world Use
MonitoringtophtopfreedfiostatServer health checks, alert setup
TroubleshootinggreptailjournalctlstraceDebug production issues
File ManagementfindgrepawksedLog analysis, file operations
NetworkingnetstatcurlpingtracerouteConnectivity debugging
Process ManagementpskillnohupsystemctlService management
Automationcronbash scriptssedawkRoutine task automation
SecuritychmodchowniptablessudoAccess control, hardening

Next Steps for Mastery

  1. Daily Practice: Solve one Linux challenge daily

  2. Build Projects: Set up a home server or cloud instance

  3. Contribute: Help with open-source projects

  4. Certifications: Consider Linux Foundation or Red Hat certifications

  5. Real Experience: Volunteer for Linux-related tasks at work


Remember: In DevOps interviews, they don't just want command syntax. They want to see problem-solving approach. Always explain:

  1. What you're checking

  2. Why you're checking it

  3. What the results mean

  4. What you'll do next


Additional Resources

  • Practice Platforms: Linuxzoo, OverTheWire, HackTheBox

  • Books: "The Linux Command Line", "How Linux Works"

  • Courses: Linux Foundation courses, Red Hat training

  • Communities: r/linuxadmin, DevOps Stack Exchange


Ready for Linux interviews? Practice these scenarios until they become second nature! 🐧

Need specific scenario help? Ask in comments below! 👇

Comments

Popular posts from this blog

Introduction to Terraform – The Future of Infrastructure as Code

  Introduction to Terraform – The Future of Infrastructure as Code In today’s fast-paced DevOps world, managing infrastructure manually is outdated . This is where Terraform comes in—a powerful Infrastructure as Code (IaC) tool that allows you to define, provision, and manage cloud infrastructure efficiently . Whether you're working with AWS, Azure, Google Cloud, or on-premises servers , Terraform provides a declarative, automation-first approach to infrastructure deployment. Shape Your Future with AI & Infinite Knowledge...!! Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! In today’s digital-first world, agility and automation are no longer optional—they’re essential. Companies across the globe are rapidly shifting their operations to the cloud to keep up with the pace of innovatio...

📊 Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd

  Monitoring & Logging in Kubernetes – Tools like Prometheus, Grafana, and Fluentd Monitoring and logging are essential for maintaining a healthy and well-performing Kubernetes cluster. In this guide, we’ll cover why monitoring is important, key monitoring tools like Prometheus and Grafana, and logging tools like Fluentd to help you gain visibility into your cluster’s performance and logs. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction In today’s fast-paced cloud-native environment, Kubernetes has emerged as the de-facto container orchestration platform. But deploying and managing applications in Kubernetes is just half the ba...

🔒 Kubernetes Security – RBAC, Network Policies, and Secrets Management

  Kubernetes Security – RBAC, Network Policies, and Secrets Management Security is a critical aspect of managing Kubernetes clusters. In this guide, we'll cover essential security mechanisms like Role-Based Access Control (RBAC) , Network Policies , and Secrets Management to help you secure your Kubernetes environment effectively. Shape Your Future with AI & Infinite Knowledge...!! Want to Generate Text-to-Voice, Images & Videos? http://www.ai.skyinfinitetech.com Read In-Depth Tech & Self-Improvement Blogs http://www.skyinfinitetech.com Watch Life-Changing Videos on YouTube https://www.youtube.com/@SkyInfinite-Learning Transform Your Skills, Business & Productivity – Join Us Today! 🚀 Introduction: Why Kubernetes Security Is Non-Negotiable As Kubernetes becomes the backbone of modern cloud-native infrastructure, security is no longer optional—it’s mission-critical . With multiple moving parts like containers, pods, services, nodes, and more, Kuberne...