Most Asked Linux Interview Questions [2025 Updated]
Master the most asked Linux interview questions for 2025 with this updated guide featuring 101 questions and answers for freshers 2025 and experienced professionals 2025. Covering Linux fundamentals, Linux command line, Linux administration, shell scripting, networking, security, containers, cloud, and real-time Linux scenario-based troubleshooting, it prepares you for DevOps 2025 roles. With advanced Linux tools like Docker, Kubernetes, and Ansible, this resource ensures success in technical interviews.
![Most Asked Linux Interview Questions [2025 Updated]](https://www.devopstraininginstitute.com/blog/uploads/images/202509/image_870x_68b81b29190a9.jpg)
Core Linux Concepts
1. What is Linux, and what are its key components?
Linux is an open-source, Unix-like operating system known for stability and flexibility. Key components:
- Kernel: Manages hardware, processes, and memory.
- Shell: Interfaces users with the kernel (e.g., Bash).
- File System: Organizes data (e.g., ext4).
- Utilities: Tools like
ls
,grep
. - Libraries: Shared code (e.g., glibc).
These enable Linux to power servers, desktops, and IoT devices efficiently.
2. How does Linux differ from other operating systems?
Linux is open-source, allowing customization, unlike Windows or macOS. It’s stable (long uptimes), secure (strong permissions), and lightweight, supporting diverse hardware. Its community-driven development ensures frequent updates, making it ideal for enterprise servers compared to proprietary systems.
3. What is the Linux kernel’s role?
The kernel manages hardware interactions, process scheduling, memory allocation, and system calls. It acts as a bridge between applications and hardware, ensuring efficient resource use. For example, it schedules CPU time for processes like nginx
.
4. What are Linux distributions, and how do they vary?
Distributions (e.g., Ubuntu, CentOS, Arch) customize Linux with different package managers (APT, DNF, Pacman), release models (stable vs. rolling), and use cases (desktop, server). Ubuntu is beginner-friendly, CentOS is enterprise-focused, and Arch is customizable.
5. How do you check the Linux version and kernel?
Commands:
cat /etc/os-release
: Shows distro details (e.g., Ubuntu 22.04).uname -r
: Displays kernel version (e.g., 5.15.0-73).
These help verify compatibility or troubleshoot issues.
6. What is a shell, and what are common types?
A shell interprets commands for the kernel. Types:
- Bash: Default, scripting-friendly.
- Zsh: Advanced autocomplete.
- Fish: User-friendly syntax.
Example:bash -c "ls -l"
lists files in long format.
7. What is the difference between a process and a thread?
- Process: Independent program with its own memory (e.g.,
httpd
). - Thread: Lightweight unit within a process, sharing memory.
Useps -eLf
to view. Processes are isolated, threads are faster but riskier.
8. What is the purpose of the /etc
directory?
/etc
stores system configuration files, like /etc/passwd
(users), /etc/fstab
(mounts), and /etc/hosts
(DNS). It’s critical for defining system behavior and services.
9. How does Linux handle multitasking?
Linux uses preemptive multitasking, with the kernel’s scheduler (e.g., CFS) allocating CPU time based on process priority. Tools like nice
adjust priorities, ensuring efficient resource use (e.g., prioritizing a database process).
10. What is the root user’s role?
The root user (UID 0) has full system access for tasks like software installation or kernel changes. Use sudo
for secure root command execution to minimize risks.
File System and Storage
11. What is the Filesystem Hierarchy Standard (FHS)?
FHS organizes directories: /bin
(binaries), /home
(user files), /var
(logs), /etc
(configs). It standardizes file locations across distros, simplifying management and backups.
12. What are common Linux filesystem types?
- ext4: Reliable, general-purpose.
- XFS: High-performance for large files.
- Btrfs: Supports snapshots, compression.
- NFS: Network file sharing.
Example: ext4 suits most servers, XFS excels in data-heavy environments.
13. How do you check disk usage?
df -h
: Shows disk space in GB (e.g.,/dev/sda1: 60G used
).du -sh /path
: Summarizes directory usage.
Helps identify storage bottlenecks.
14. What is Logical Volume Manager (LVM)?
LVM enables dynamic disk management. Components:
- Physical Volumes (PVs): Disks/partitions.
- Volume Groups (VGs): PV pools.
- Logical Volumes (LVs): Virtual partitions.
Example:lvresize
adjusts LV size without downtime.
15. How do you create a filesystem?
Steps:
- Partition:
fdisk /dev/sdb
. - Format:
mkfs.ext4 /dev/sdb1
. - Mount:
mount /dev/sdb1 /mnt
. - Add to
/etc/fstab
:/dev/sdb1 /mnt ext4 defaults 0 2
.
Verify withdf -h
.
16. What is the difference between hard and soft links?
- Hard Link: Shares inode, same data (e.g.,
ln file1 file2
). - Soft Link: Points to path (e.g.,
ln -s file1 link1
).
Hard links persist if the original is deleted; soft links break.
17. How do you repair a corrupted filesystem?
Run: fsck /dev/sda1
(unmounted). Use -y
to auto-fix. Backup first to avoid data loss. Verify with mount
.
18. What is the /proc
filesystem?
/proc
is a virtual filesystem with runtime info (e.g., /proc/cpuinfo
for CPU, /proc/meminfo
for memory). It’s used for monitoring without physical storage.
19. How do you mount an NFS share?
Install: apt install nfs-common
. Mount: mount -t nfs server:/export /mnt
. Add to /etc/fstab
: server:/export /mnt nfs defaults 0 0
. Verify with df -h
.
20. What is swap space, and how do you configure it?
Swap extends RAM on disk. Steps:
- Create:
mkswap /dev/sdb1
. - Enable:
swapon /dev/sdb1
. - Add to
/etc/fstab
:/dev/sdb1 swap swap defaults 0 0
.
Check withfree -h
. Size: 1-2x RAM.
System Administration
21. How do you check system uptime?
Run uptime
or cat /proc/uptime
. Example: uptime
shows 5 days, 2:15
. Assesses system stability.
22. What is /etc/passwd
used for?
Stores user details: username, UID, GID, home, shell (e.g., user:x:1000:1000:/home/user:/bin/bash
). Edited via useradd
.
23. How do you add a user?
sudo useradd -m -s /bin/bash username
sudo passwd username
-m
creates home, -s
sets shell. Verify with id username
.
24. How do you change file permissions?
Use chmod
:
chmod 755 file
: Owner rwx, others rx.chmod u+x file
: Adds execute for owner.
Verify withls -l
.
25. What are default file permissions?
- Files: 664 (rw-rw-r--).
- Directories: 775 (rwxrwxr-x).
Set by umask (e.g.,umask 002
). Check withls -l
.
26. How do you manage services with systemd?
Commands:
- Start:
systemctl start nginx
. - Enable:
systemctl enable nginx
. - Status:
systemctl status nginx
.
Example:systemctl restart sshd
.
27. How do you schedule a cron job?
Edit: crontab -e
. Example:
0 2 * * * /backup.sh
Runs daily at 2 AM. Verify with crontab -l
.
28. How do you check running processes?
ps aux
: Lists all processes.top
/htop
: Real-time monitoring.
Example:ps aux | grep nginx
.
29. How do you kill a process?
kill 1234
: Sends SIGTERM.kill -9 1234
: Forces SIGKILL.killall nginx
: Kills by name.
Verify withps
.
30. What is the difference between kill
and killall
?
kill
: Targets PID (e.g.,kill 1234
).killall
: Targets process name (e.g.,killall httpd
).killall
is broader, riskier.
Networking and Security
31. How do you check network configuration?
ip addr
: Shows IPs/interfaces.ip route
: Routing table.nmcli
: NetworkManager settings.
Example:ip addr show eth0
.
32. What is /etc/hosts
used for?
Maps IPs to hostnames (e.g., 127.0.0.1 localhost
). Used before DNS. Edit with nano /etc/hosts
.
33. How do you set a static IP?
For Ubuntu, edit /etc/netplan/01-netcfg.yaml
:
network:
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
Apply: sudo netplan apply
. Verify: ip addr
.
34. How do you configure iptables?
Example:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -j DROP
Allows SSH, drops others. Save: iptables-save
.
35. How do you secure SSH?
Edit /etc/ssh/sshd_config
:
Port 2222
PermitRootLogin no
PasswordAuthentication no
Use key-based auth:ssh-keygen
,ssh-copy-id
. Restart:systemctl restart sshd
.
36. What is SELinux, and how does it work?
SELinux enforces mandatory access controls via policies. Modes: enforcing, permissive, disabled. Example: setsebool -P httpd_can_network_connect 1
. Check: getenforce
.
37. How do you check open ports?
ss -tuln
: Lists listening ports.netstat -tuln
: Alternative.nmap localhost
: Scans ports.
Example:ss -tuln
showstcp 0.0.0.0:22
.
38. What is /etc/resolv.conf
?
Defines DNS servers (e.g., nameserver 8.8.8.8
). Managed by NetworkManager or edited manually. Verify with dig google.com
.
39. How do you configure firewalld?
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
Opens port 80. Check: firewall-cmd --list-all
.
40. How do you set up NTP?
Install: apt install ntp
. Edit /etc/ntp.conf
: server pool.ntp.org
. Restart: systemctl restart ntp
. Verify: ntpstat
.
System Performance and Monitoring
41. How do you monitor CPU/memory usage?
top
/htop
: Real-time stats.free -h
: Memory usage (e.g.,used: 2G
).vmstat
: CPU, I/O stats.
Example:htop
shows process usage.
42. What is the role of top
?
Displays CPU, memory, and process stats (e.g., %CPU
, PID
). Example: top
identifies high-CPU processes like mysql
.
43. How do you check disk I/O?
iostat -x
: Read/write rates.iotop
: Per-process I/O.
Example: Highiostat
wait indicates bottlenecks.
44. How do you interpret load average?
Seen in uptime
(e.g., 0.50, 0.30, 0.20
). Values > CPU cores indicate overload. Check with top
.
45. How do you detect a memory leak?
Monitor with free -h
, check process with pmap -x
. Example: Rising memory for nginx
suggests a leak.
46. What is sar
used for?
Collects performance data. Example: sar -u 1 5
shows CPU stats every second for 5 iterations. Install: apt install sysstat
.
47. How do you monitor network traffic?
iftop
: Real-time bandwidth.nload
: Interface stats.tcpdump -i eth0
: Packet capture.
Example:iftop -i eth0
.
48. What is journalctl
?
Queries systemd logs. Example: journalctl -u nginx
shows nginx logs. Use -f
for real-time.
49. How do you tune performance with nice
?
Set priority: nice -n 10 command
(low). Adjust running process: renice 5 -p 1234
. Example: nice -n -10 mysql
.
50. What is vmstat
?
Reports memory, CPU, I/O. Example: vmstat 1 5
shows stats every second. High wa
indicates disk issues.
Shell Scripting and Automation
51. What is a shell script?
A file with commands (e.g., Bash) to automate tasks. Example:
#!/bin/bash
echo "Disk usage"
df -h
Run: bash script.sh
.
52. How do you make a script executable?
chmod +x script.sh
Run: ./script.sh
. Verify: ls -l
.
53. What is the difference between source
and ./
?
source script.sh
: Runs in current shell, affects environment../script.sh
: New shell, no parent impact.
Example:source ~/.bashrc
.
54. How do you use variables in scripts?
path="/var/log"
echo "Logs in $path"
Stores dynamic data for flexibility.
55. What are exit codes?
Indicate success (0) or failure (non-zero). Check: echo $?
. Example:
ls /nonexistent
echo $? # Outputs 2
56. How do you schedule a script with cron?
crontab -e
0 3 * * * /script.sh
Runs at 3 AM. Verify: crontab -l
.
57. What is grep
in scripting?
Searches text. Example:
if grep "error" /var/log/syslog; then echo "Issues found"; fi
Filters logs for automation.
58. How do you use awk
?
Processes text by fields. Example: awk '{print $1}' /etc/passwd
prints usernames. Useful for log parsing.
59. What is a pipe (|
)?
Passes output to another command. Example: ls -l | grep ".txt"
lists text files. Chains commands for workflows.
60. How do you handle script errors?
cp file.txt /backup || { echo "Failed"; exit 1; }
Logs errors to /var/log/script.log
.
Package Management
61. What is a package manager?
Installs, updates, removes software. Examples:
- APT (Ubuntu):
apt install nginx
. - DNF (CentOS):
dnf install httpd
.
Resolves dependencies automatically.
62. How do you install a package in Ubuntu?
sudo apt update
sudo apt install nginx
Verify: dpkg -l | grep nginx
.
63. How do you remove a package in CentOS?
sudo dnf remove httpd
Check: rpm -qa | grep httpd
.
64. What is apt
vs. apt-get
?
apt
: User-friendly wrapper.apt-get
: Low-level tool for scripts.
Example:apt install
for interactive use.
65. How do you add a repository?
Ubuntu: Add to /etc/apt/sources.list
:
deb http://repo.url focal main
Update: apt update
. CentOS: Edit /etc/yum.repos.d/
.
66. What is a PPA in Ubuntu?
Personal Package Archive for third-party software. Example:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
67. How do you list installed packages?
- Ubuntu:
dpkg -l
. - CentOS:
rpm -qa
.
Example:dpkg -l | grep nginx
.
68. What is a source vs. binary package?
- Source: Code to compile.
- Binary: Precompiled (e.g.,
.deb
).
Binaries are faster to install.
69. How do you update packages?
- Ubuntu:
apt update && apt upgrade
. - CentOS:
dnf update
.
Example:apt upgrade -y
.
70. What is yum
vs. dnf
?
yum
: Older, slower.dnf
: Modern, faster dependency resolution.
Example:dnf update
in CentOS 8+.
User and Permission Management
71. How do you modify a user’s group?
sudo usermod -aG sudo username
Adds to sudo group. Verify: groups username
.
72. What is /etc/group
?
Lists groups and members (e.g., sudo:x:27:user1
). Edit with groupadd
.
73. How do you lock a user account?
passwd -l username
Unlock: passwd -u username
. Prevents login.
74. What are sticky bits?
Restrict deletion in shared directories. Set:
chmod +t /tmp
Shows as t
in ls -ld
.
75. How do you set default permissions?
umask 022
Results in 644 (files), 755 (dirs). Set in ~/.bashrc
.
76. What is su
vs. sudo
?
su
: Switches user, needs password.sudo
: Runs command as another user.sudo
is safer, configurable via/etc/sudoers
.
77. How do you delegate sudo commands?
Edit /etc/sudoers
with visudo
:
username ALL=(ALL) /usr/bin/apt
Verify: sudo -l
.
78. What is /etc/shadow
?
Stores encrypted passwords, readable only by root (e.g., user:$6$hash:...
).
79. How do you change a user’s shell?
sudo chsh -s /bin/zsh username
Verify: cat /etc/passwd
.
80. What is setuid?
Runs executable with owner’s permissions. Example:
chmod u+s /usr/bin/passwd
Shows rws
in ls -l
.
Backup and Recovery
81. How do you create a full system backup?
tar -cvpzf /backup/full_backup.tar.gz --exclude=/backup / --exclude=/proc
Restore: tar -xpzf
. Schedule via cron.
82. What is rsync
for backups?
Synchronizes files efficiently. Example:
rsync -avh /source /backup
--delete
mirrors source.
83. How do you restore a file from a backup?
For tar
:
tar -xpzf /backup/full_backup.tar.gz -C /restore path/to/file
Verify: ls /restore
.
84. What is an LVM snapshot?
Captures volume state. Create:
lvcreate -s -n snap -L 5G /dev/vgname/lvname
Backup, then remove: lvremove
.
85. How do you back up a database?
MySQL: mysqldump -u root -p database > backup.sql
.
Restore: mysql < backup.sql
. Schedule with cron.
86. What is /etc/fstab
in recovery?
Defines mounts (e.g., /dev/sda1 / ext4 defaults 0 1
). Fix in recovery mode if boot fails.
87. How do you recover a corrupted bootloader?
Boot live USB, chroot:
mount /dev/sda1 /mnt
chroot /mnt
grub-install /dev/sda
update-grub
88. What is dd
for backups?
Copies raw data:
dd if=/dev/sda of=/backup/disk.img bs=64K
Restore: dd if=/backup/disk.img of=/dev/sda
.
89. How do you automate backups?
Script:
#!/bin/bash
rsync -av /data /backup
Cron: 0 1 * * * /backup.sh
.
90. What is incremental vs. differential backup?
- Incremental: Changes since last backup.
- Differential: Changes since last full backup.
Usersync
for incremental.
Troubleshooting and Diagnostics
91. How do you troubleshoot a boot failure?
Boot live USB, check /mnt/var/log/syslog
, verify /etc/fstab
, run fsck
, reinstall GRUB: grub-install
.
92. What is dmesg
?
Shows kernel logs. Example: dmesg | grep disk
for disk errors. Use with journalctl
.
93. How do you troubleshoot network issues?
- Check:
ip link
,ping 8.8.8.8
. - DNS:
dig google.com
. - Firewall:
iptables -L
.
Example: Fix missingnameserver
in/etc/resolv.conf
.
94. How do you find high CPU usage?
Use top
, identify process (e.g., mysql
at 90%). Debug: strace -p
.
95. What is strace
?
Traces system calls. Example: strace -p 1234
diagnoses hangs.
96. How do you troubleshoot a service failure?
Check: systemctl status nginx
, logs: journalctl -u nginx
. Restart: systemctl restart nginx
.
97. What is lsof
?
Lists open files/sockets. Example: lsof -i :80
shows port 80 usage.
98. How do you recover a deleted open file?
Find process: lsof | grep filename
, copy: cp /proc/
.
99. What is netstat
?
Shows connections. Example: netstat -tuln
lists ports. Replaced by ss
.
100. How do you diagnose a slow system?
Check CPU/memory: top
, disk: iostat
, network: iftop
. Example: High I/O wait suggests disk issues.
101. What skills define a top Linux admin in 2025?
- Scripting (Bash, Python).
- Automation (Ansible, Terraform).
- Containers (Docker, Kubernetes).
- Cloud integration (AWS, Azure).
- Security (SELinux, firewalls).
Practice with labs like TryHackMe or AWS.
Tips to Ace Your Linux Interview
- Hands-On Labs: Use VirtualBox or cloud platforms to practice commands and configurations.
- Master Tools: Be fluent in
grep
,awk
,systemctl
, andip
. - Scripting: Write automation scripts for backups or monitoring.
- Stay Current: Understand 2025 trends like containers, cloud, and IPv6.
- Certifications: Consider RHCSA or LFCS for credibility.
- Explain Clearly: Simplify complex topics like LVM or SELinux for interviewers.
What's Your Reaction?






