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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
# 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:
#!/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:
#!/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:
#!/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:
#!/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:
# 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:
"How do you find a file that was modified yesterday?"
"What's the difference between soft link and hard link?"
"How do you check open files by a process?"
"Explain load average in simple terms"
"How to schedule a job that runs every weekday at 2 PM?"
"What's the difference between
killandkill -9?""How to check if a port is open on remote server?"
"Explain
chmod 755in detail""How to monitor real-time disk I/O?"
"What's the purpose of
/etc/fstab?"
Real DevOps Workflow Example
Deploying an Application:
#!/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:
# 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:
Set up a web server (Nginx/Apache)
Configure firewall rules
Set up monitoring with Prometheus
Create backup automation
Build a CI/CD pipeline
Configure log aggregation
Summary Table: Linux DevOps Skills
| Skill Category | Key Commands | Real-world Use |
|---|---|---|
| Monitoring | top, htop, free, df, iostat | Server health checks, alert setup |
| Troubleshooting | grep, tail, journalctl, strace | Debug production issues |
| File Management | find, grep, awk, sed | Log analysis, file operations |
| Networking | netstat, curl, ping, traceroute | Connectivity debugging |
| Process Management | ps, kill, nohup, systemctl | Service management |
| Automation | cron, bash scripts, sed, awk | Routine task automation |
| Security | chmod, chown, iptables, sudo | Access control, hardening |
Next Steps for Mastery
Daily Practice: Solve one Linux challenge daily
Build Projects: Set up a home server or cloud instance
Contribute: Help with open-source projects
Certifications: Consider Linux Foundation or Red Hat certifications
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:
What you're checking
Why you're checking it
What the results mean
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
Post a Comment