Linux Interview Questions and Practice Labs
# CHAPTER 19
Linux Interview Questions and Practice Labs
1. Introduction
Reading about Linux commands is fundamentally different from executing them under the high-pressure scrutiny of a technical job interview. When interviewing for a Systems Administrator, Cloud Engineer, or DevOps role, the interviewer will not ask you for definitions. They will present you with broken server scenarios and ask you to verbally articulate the exact CLI forensic workflow required to isolate the fault. In this chapter, we have curated high-impact, real-world technical interview questions and scenario-based troubleshooting labs designed to synthesize everything you have learned across the filesystem, process management, and networking chapters.2. Learning Objectives
By the end of this chapter, you will be able to:- Confidently articulate solutions to complex Linux administration interview questions.
- Execute rapid-fire command combinations using pipes and filters.
- Demonstrate a logical, bottom-up troubleshooting methodology for server outages.
- Decipher and fix broken Bash scripts.
-
Synthesize multiple Linux tools (e.g.,
ps,grep,kill) into single workflows.
3. Core Technical Interview Questions
Q1: "A user complains that a website hosted on our Linux server is throwing a 502 Bad Gateway error. Walk me through your exact command-line troubleshooting steps from the moment you SSH into the machine." *How to answer (The Gold Standard):*
-
1.
Check Resources: "First, I run
toporfree -mto ensure the server isn't simply out of RAM or suffering a CPU lockup."
-
2.
Check the Service: "Next, I run
sudo systemctl status nginx(or apache2) to see if the web daemon has crashed."
-
3.
Check the Ports: "I run
sudo ss -tulpn | grep 80to verify the server is actually actively listening on the HTTP port."
-
4.
Check the Logs: "If the service is running but throwing errors, I will inspect the application logs using
tail -f /var/log/nginx/error.logor query the system journal usingjournalctl -u nginxto find the exact syntax or database connection error causing the 502."
Q2: "You type ls -l and see a file with the permissions drwxr-x---. Explain exactly what this means, who has access, and how you would change it to 755."
*How to answer:* "The d means it is a directory. The owner has read, write, and execute permissions (rwx, which is a 7). The group has read and execute permissions (r-x, which is a 5). The rest of the world has zero access (---, which is a 0). To change it to 755 so the world can enter the directory, I would run the command chmod 755 [directoryname]."
Q3: "You deleted a massive 100GB log file using rm, but df -h shows the hard drive is still 100% full. Why did this happen, and how do you fix it?"
*How to answer:* "In Linux, if a running process (like a web server) holds an active file handle open, deleting the filename from the directory tree does not release the physical data from the disk. To fix it, I would use the lsof +L1 (List Open Files) command to find the specific "deleted" file, identify the PID of the application holding it, and then restart that specific service using systemctl restart [service]. This forces the app to release the handle, instantly freeing the 100GB."
4. CLI Rapid-Fire Drills
Interviewers often ask you to accomplish tasks using one-liners.Drill 1: The Log Extraction
*Task:* Search the /var/log/auth.log file for the word "Failed". Do not show case sensitivity. Show only the last 10 occurrences.
*Answer:* grep -i "failed" /var/log/auth.log | tail -n 10
Drill 2: The Rogue Process
*Task:* A script named cryptominer.sh is running. Find its PID and kill it instantly using a single command string.
*Answer:* ps aux | grep "cryptominer.sh" (Find the PID, e.g., 5043). Then kill -9 5043.
*(Bonus point answer: killall -9 cryptominer.sh)*
Drill 3: The Archival Backup
*Task:* Compress the /etc configuration directory into a gzip tarball named backup.tar.gz and place it in the /tmp folder.
*Answer:* sudo tar -czvf /tmp/backup.tar.gz /etc
5. Troubleshooting Scenario Labs
Scenario 1: The "Command Not Found" Panic
*The Setup:* A developer writes a custom Python script, saves it as build.py in their /home/dev/scripts folder, makes it executable with chmod +x build.py, and types build.py. The terminal says Command Not Found.
*The Solution:* The terminal only searches directories listed in the $PATH environment variable. The developer's personal script folder is not in the PATH. They must execute it using a relative path (./build.py) or an absolute path (/home/dev/scripts/build.py), or they must add the folder to their ~/.bashrc file via an export statement.
Scenario 2: The Locked Out Admin
*The Setup:* You configure a new Ubuntu server. You install UFW (the firewall). You change the SSH port in /etc/ssh/sshd_config from 22 to 2222. You type sudo ufw enable. You log out. You can never log back in.
*The Solution:* You enabled the firewall with a default deny policy, but you forgot to tell the firewall about the new SSH port! You should have executed sudo ufw allow 2222 BEFORE enabling UFW. Because you locked the only door, you must use the cloud provider's emergency console GUI to log in and fix the firewall rules.
6. Deciphering Broken Bash Scripts
Interviewers will hand you printed code and ask you to find the bug.*The Broken Script:*
*The Error:* The script lacks the mandatory spaces inside the if statement brackets. It must be written as if [ $TARGET = "/var/log" ]. Without the spaces, Bash interprets [ as a missing command and crashes.
7. Preparing for the Technical Assessment
When an interviewer presents a scenario, never guess the final answer immediately. Senior engineers demonstrate *methodology*.-
1.
Acknowledge the OSI Model: Always state you will check Layer 1/2 (cables/interfaces via
ip a), then Layer 3 (routing viaping), then Layer 4 (ports viass), then Layer 7 (application logs viajournalctl).
-
2.
Read the Logs: The ultimate trump card in a Linux interview is saying, "Before making any changes to the system, I would inspect the application logs in
/var/logorsystemdto identify the exact error code." Guessing is dangerous; logs are facts.
8. Summary
In Chapter 19, we stress-tested your foundational CLI knowledge against the rigor of a professional technical interview. We practiced articulating complex forensic workflows, such as identifying "deleted" files still occupying disk space and diagnosing 502 Bad Gateway errors. We executed rapid-fire command chaining utilizing pipes (|), grep, and tail. Most importantly, we solidified a logical, log-driven troubleshooting methodology, proving that you are not just a user who memorized command syntax, but an engineer who can methodically dissect and repair a shattered system.