Table of contents
1.
Introduction
2.
Beginner Level Linux Interview Questions
2.1.
Question 1: Define Linux. 
2.2.
Question 2: Explain the features of Linux.
2.3.
Question 3: What are the components of Linux?
2.4.
Question 4: What do you mean by redirection?
2.5.
Question 5: What is the use of Swap space in Linux?
2.6.
Question 6: What do you mean by LILO?
2.7.
Question 7: Define samba.
2.8.
Question 8: To check memory status, which command is used?
2.9.
Question 9: What is the use of run-level command?
2.10.
Question 10: What do you mean by Grep command?
2.11.
Question 11: What is the command to check the current Linux kernel version?
2.12.
Question 12: How do you list all files in a directory, including hidden files?
2.13.
Question 13: What is a Linux distribution?
2.14.
Question 14: How do you check disk usage in Linux?
2.15.
Question 15: How can you search for a specific file in Linux?
3.
Intermediate Level Linux Interview Questions
3.1.
Question 16: Define the Zombie process.
3.2.
Question 17: What types of file permissions are there in Linux?
3.3.
Question 18: Define Shell Script.
3.4.
Question 19: Define Linux Kernel.
3.5.
Question 20: What are some common Linux variants?
3.6.
Question 21: Write the command for user management.
3.7.
Question 22: What are some advantages of open source?
3.8.
Question 23: Explain BASH.
3.9.
Question 24: What do you know about inode and process id?
3.10.
Question 25: What do you know about Virtual Desktops?
3.11.
Question 26: What is the difference between su and sudo?
3.12.
Question 27: How do you view running processes in Linux?
3.13.
Question 28: How do you schedule a cron job in Linux?
3.14.
Question 29: How do you kill a process in Linux?
3.15.
Question 30: How do you mount and unmount a file system in Linux?
4.
Advanced Level Linux Interview Questions
4.1.
Question 31: Differentiate between Hard and Soft links.
4.2.
Question 32: What is Anacron and Cron?
4.3.
Question 33: Differentiate between UNIX and LINUX.
4.4.
Question 34: Define GUI.
4.5.
Question 35: What are the commands used to check the memory status?
4.6.
Question 36: Differentiate between BASH and DOS.
4.7.
Question 37: Write the various process states in Linux.
4.8.
Question 38: What are the various modes of vi editors?
4.9.
Question 39: What do you mean by Linux Directory Commands?
4.10.
Question 40: What are Process Management System Calls in Linux?
4.11.
Question 41: How do you compress and extract files in Linux using tar?
4.12.
Question 42: How do you create a new user in Linux?
4.13.
Question 43: What is LVM?
4.14.
Question 44: How do you monitor disk I/O in Linux?
4.15.
Question 45: What is cgroups?
5.
Linux OS Internals Interview Questions
5.1.
Question 46: What is the role of the Linux Kernel?
5.2.
Question 47: What is a system call in Linux?
5.3.
Question 48: What is the difference between user mode and kernel mode in Linux?
5.4.
Question 49: What are kernel modules, and how do you manage them?
5.5.
Question 50: Explain process scheduling in the Linux kernel.
5.6.
Question 51: What is the difference between a process and a thread in Linux?
5.7.
Question 52: How does the Linux kernel handle memory management?
5.8.
Question 53: What is an inode in Linux?
5.9.
Question 54: What is the purpose of the fork() system call?
5.10.
Question 55: How does the Linux kernel handle interrupts?
6.
Linux Admin Interview Questions
6.1.
Question 56: What is the purpose of the /etc/passwd file?
6.2.
Question 57: How do you check system resource usage in Linux?
6.3.
Question 58: What is a symbolic link and how do you create one?
6.4.
Question 59: How do you find large files on a Linux system?
6.5.
Question 60: What is the purpose of the cron daemon?
6.6.
Question 61: How do you check open ports on a Linux system?
6.7.
Question 62: What is the purpose of the /etc/fstab file?
6.8.
Question 63: How do you troubleshoot high CPU usage on a Linux server?
6.9.
Question 64: What is SELinux and what are its modes?
6.10.
Question 65: How do you set up a basic firewall using iptables?
7.
Linux Troubleshooting Interview Questions
7.1.
Question 66: How do you check disk space usage on a Linux system?
7.2.
Question 67: How can you troubleshoot high CPU usage on a Linux system?
7.3.
Question 68: What command can you use to check for open ports and services?
7.4.
Question 69: How do you check and free up memory on a Linux system?
7.5.
Question 70: How do you find large files on a Linux system that might be filling up disk space?
7.6.
Question 71: How can you troubleshoot a system that won’t boot?
7.7.
Question 72: How do you check for hardware issues on a Linux system?
7.8.
Question 73: What are some ways to troubleshoot network connectivity issues in Linux?
7.9.
Question 74: How do you check the system logs for troubleshooting purposes?
7.10.
Question 75: How can you troubleshoot a slow system performance issue in Linux?
8.
Linux Networking Interview Questions
8.1.
Question 76: What is the purpose of the /etc/hosts file?
8.2.
Question 77: How do you check the IP address of a Linux system?
8.3.
Question 78: What is the difference between TCP and UDP?
8.4.
Question 79: Explain the purpose of the netstat command.
8.5.
Question 80: What is a subnet mask and how is it used?
8.6.
Question 81: How do you set a static IP address in Linux?
8.7.
Question 82: What is NAT and how does it work?
8.8.
Question 83: How do you troubleshoot network connectivity issues in Linux?
8.9.
Question 84: What is the purpose of the traceroute command?
8.10.
Question 85: Explain the difference between a switch and a router.
9.
Linux Interview MCQs
9.1.
Question 1: Which command is used to list all files in a directory, including hidden files?
9.2.
Question 2: What is the command to check the current working directory in Linux?
9.3.
Question 3: Which command is used to change file permissions in Linux?
9.4.
Question 4: What does the mkdir command do?
9.5.
Question 5: How do you view the contents of a file in Linux?
9.6.
Question 6: Which command is used to display the running processes in Linux?
9.7.
Question 7: What is the use of the grep command in Linux?
9.8.
Question 8: What does the df command display?
9.9.
Question 9: Which file contains user account information in Linux?
9.10.
Question 10: What is the purpose of the kill command in Linux?
10.
Frequently Asked Questions
10.1.
Explain about Linux terminal.
10.2.
Why is Linux better?
10.3.
What are the disadvantages of Linux?
11.
Conclusion
Last Updated: Sep 23, 2024
Medium

Linux Interview Questions

Author Sinki Kumari
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Linux is an open-source computer operating system based on the Unix operating system (OS). It oversees the hardware and resources of a system, including the CPU, memory, and storage, as well as software and hardware communication. It's based on the Linux kernel and is free to download and use.

It can also be installed on mobile phones, laptops, desktops, notebooks, and other devices. Ubuntu, Debian, SUSE Linux, Gentoo, and different Linux OS flavours are available. 

Linux Interview Questions.

Beginner Level Linux Interview Questions

Question 1: Define Linux. 

Answer: Linux is the most widely used open-source operating system. It is a UNIX-based operating system. It can support almost every computer platform, including ARM and SPARC. It directly manages the resources and hardware of a system, which include memory, CPU, and storage. Linux also handles the communication between software and hardware. 

Question 2: Explain the features of Linux.

Answer: There are several  features of linux operating system. Some of them are:

  • Linux is free and open source.
     
  • It is more secure.
     
  • It is robust and adaptable.
     
  • It is a multiprogramming system. This means that Linux allows more than one program to run at the same time.

Question 3: What are the components of Linux?

Answer: The components of Linux are as follows. 

  • Kernel: The kernel consists of various modules which interact directly with the hardware. It is a core part of Linux.
     
  • System Utility: They are responsible to do specialized and individual-level tasks.
     
  • System Library: Using these libraries, we can implement the operating system's functionalities.
     
  • Hardware: It includes a mouse, keyboard, display, and CPU.
     
  • Shell: Shell is an environment where we can run programs and commands.

Question 4: What do you mean by redirection?

Answer: Redirection in the Linux operating system allows to change the standard input and output devices. We can redirect the programs or files to specified locations asked by the user. For redirections, Metacharacters are used. 

Question 5: What is the use of Swap space in Linux?

Answer: In Linux, Swap space is used when the RAM is full. It may be considered as a physical memory substitute. The main function of swap space is to substitute disk space for RAM memory. Basically, swap space is nothing but an extension of RAM.

Question 6: What do you mean by LILO?

Answer: LILO is an abbreviation for Linux Loader. It is used to load Linux into memory and start our operating system. It is also called a boot manager, which facilitates a dual boot of a computer system.

Question 7: Define samba.

Answer: Samba is nothing but open-source software. It can run many operating systems, including IBM and OpenVMS. Samba connects Linux machines to Microsoft network resources by providing SMB support. Samba is stable and secure.

Question 8: To check memory status, which command is used?

Answer: “free” is the most used command to check the memory status in Linux. Other than the “free” command. “Cat,” “vmstat,” “top” and “htop” commands are used to check the memory status.

Question 9: What is the use of run-level command?

Answer: After boot, the run-level command is helpful in defining the state of the machine. By default, the run level of the system is set by the system administrator. 

Question 10: What do you mean by Grep command?

Answer: Grep command in Linux is a filter for the global search for Regular Expressions. This command is used to search the text in the given files and Strings. Grep is the most common command which is used in Linux.

Question 11: What is the command to check the current Linux kernel version?

Answer: The command to check the current Linux kernel version is:

uname -r

Question 12: How do you list all files in a directory, including hidden files?

Answer: You can list all files in a directory, including hidden files using the following command:

ls -a

 

The -a option shows all files, including those starting with a dot (.), which are hidden files.

Question 13: What is a Linux distribution?

Answer: A Linux distribution is a version of the Linux operating system. It comes with a specific set of software packages, a kernel, and management tools. Examples include Ubuntu, Fedora, CentOS, and Debian.

Question 14: How do you check disk usage in Linux?

Answer: You can check the disk usage using the following command:

df -h

 

The -h option displays the disk usage in a human-readable format (e.g., GB, MB).

Question 15: How can you search for a specific file in Linux?

Answer: You can search for a specific file using the find command. For example:

find /path/to/directory -name "filename"

 

This command will search for "filename" in the specified directory and its subdirectories.


Moving forward, let’s discuss Intermediate Level Linux Interview Questions.

Intermediate Level Linux Interview Questions

Question 16: Define the Zombie process.

Answer: Zombie process in Linux, refers to the process that is removed  from the user system but still resides in the processor’s memory. The child process always first becomes a zombie before being deleted from the process table.

Question 17: What types of file permissions are there in Linux?

Answer: There are mainly three types of permissions in the Linux operating system:

  • READ: By using READ permission, the user can read the file.
     
  • WRITE: By using WRITE permission, the user can write a new file.
     
  • EXECUTE: By using EXECUTE permission, the user can access and run the file.

Question 18: Define Shell Script.

Answer: In the Linux operating system, a Shell script is a script or programming language which is written for the shell. This script is used to control the applications. It allows the executions of different commands that enters in the shell. It helps to create programs to perform various tasks.

Question 19: Define Linux Kernel.

Answer: Kernel is low-level software for computer systems. The kernel is a main component of the Linux operating system. It acts as a bridge between hardware and software. Whenever a computer system starts, the kernel is the first program that is loaded. The main function are:

  • Memory management
     
  • Device management
     
  • Storage management
     
  • Process management

Question 20: What are some common Linux variants?

Answer: The Linux variants are as follows:

  • CentOS
     
  • Fedora
     
  • Debian
     
  • RedHat
     
  • Ubuntu

Question 21: Write the command for user management.

Answer: The basic commands for user management are given below:

  • last: This command is used to check the last logged-in user.
     
  • chage: This command is used to view and change the user password.
     
  • useradd: This command is used to create a new user account.
     
  • userdel: This command is used to delete the user account.
     
  • chown: This command is used to change the owner of the file.
     
  • newusers: This command is used to read a file.
     
  • chsh: This command is used to change the login shell of the username.

Question 22: What are some advantages of open source?

Answer: There are many advantages of open-source. A few of them are as follows.

  • Open source makes codes available to users for free.
     
  • It allows users to add new features, debug, and correct errors in the source code.
     
  • It provides users with great security.

Question 23: Explain BASH.

Answer: BASH in the Linux operating system is a Unix shell and command processor. This software is free and acts as a Bourne shell replacement. Bash provides a user interface to interact with operating system. BASH allows users to write commands. It can also read commands from shell scripts.

Question 24: What do you know about inode and process id?

Answer: In Linux, an inode is a data structure. It carries the file information. Each and every file is given a unique name that is inode, whereas each process is provided with a unique process id.

Question 25: What do you know about Virtual Desktops?

Answer: Virtual desktop in the Linux operating system is a user interface. Whenever we face any issue on our systems regarding how to manage multiple windows, at that time virtual desktop serves as an alternative. Virtual desktops allow us to use one or more program on a clean slate as it stores remote servers.

Question 26: What is the difference between su and sudo?

Answer: 

  • su: Switches to the root user or another user account and requires the root password.
  • sudo: Executes a command as another user, typically the root user, but requires the current user's password (who must have sudo privileges).

Question 27: How do you view running processes in Linux?

Answer: You can view running processes using the ps command or top command:

  • ps: Displays information about active processes in the current shell.
ps aux
  • top: Provides a real-time view of running processes and system resource usage.
top

Question 28: How do you schedule a cron job in Linux?

Answer: Cron jobs are scheduled using the crontab file. To edit the crontab file, use:

crontab -e

 

Add a line to specify the schedule in the following format:

* * * * * /path/to/script.sh

The fields represent: minute, hour, day of the month, month, and day of the week.

Question 29: How do you kill a process in Linux?

Answer: You can kill a process using the kill command followed by the process ID (PID). First, use ps or top to find the PID of the process, then run:

kill PID

 

To forcefully terminate a process, use:

kill -9 PID

Question 30: How do you mount and unmount a file system in Linux?

Answer: 

  • Mount: To mount a file system, use the mount command. For example, to mount a USB drive:
mount /dev/sdb1 /mnt/usb
  • Unmount: To unmount the file system, use the umount command:
umount /mnt/usb


Moving forward, let’s discuss Advanced Level Linux Interview Questions.

Advanced Level Linux Interview Questions

Question 31: Differentiate between Hard and Soft links.

Answer: The difference between Hard and Soft Links are as follows.

Hard Links Soft Links
Hard links are the mirror copy of the original file. Soft links are the symbolic link to the original file.
It contains the original contents of the file.  It contains the location of the original file.
It is not used for linking directories. It is used for linking directories.

Question 32: What is Anacron and Cron?

Answer: Anacron: It is a type of program that is used to execute tasks. The tasks are executed at certain intervals. Anacron works more effectively if the machines are powered off in a day or week. It can only be used by super users, and it does not expect the system to run 24x7.

Cron: It is a program that is used to execute tasks. The tasks execute at a scheduled time. Cron work effectively if the machines run continuously. It can be scheduled by a normal user and expects the system to run 24x7.

Question 33: Differentiate between UNIX and LINUX.

Answer: The difference between UNIX and LINUX are as follows.

UNIX LINUX
UNIX is used is workstations and servers. LINUX is used in smartphones, desktops and so on..
BASH is the default shell of UNIX. BOURNE SHELL is the default shell of LINUX.
Unix is only available in English language. Linux is available in multiple languages.
Some examples are, Darwin, Solaris, and so on. Some examples are Red Hat, Ubuntu, and so on.

Question 34: Define GUI.

Answer: GUI is an abbreviation for Graphical User Interface. GUI is a human-computer interface. It allows us to interact with electronic devices, and this will happen through graphical icons and visual indicators. With the help of graphical elements or icons, it is easy to interact with the system for users. GUI is a combination of textual and graphical interaction. It uses message boxes, buttons, and menus.

Question 35: What are the commands used to check the memory status?

Answer: In Linux, we can check the status of memory by using the following commands:

  • free -m is used to display output in MB(Megabytes).
     
  • free -g is used to display output in GB(Gigabytes).

Question 36: Differentiate between BASH and DOS.

Answer: The difference between BASH and DOS are given below:

BASH DOS
BASH stands for Bourne Again Shell. DOS stands for Disk Operating System.
BASH follows conventional naming. DOS does not follow conventional naming.
It includes case-sensitive commands It includes case-insensitive commands

Also see, pwd command in linux

Question 37: Write the various process states in Linux.

Answer: The process states in Linux can be in many different states. Different process states are as follows:

  • New/Ready: This is a state where a new process is created and also ready for the run.
     
  • Running: This is a state where execution takes place.
     
  • Blocked/wait: This is a state where the process waits for the user to provide input.
     
  • Terminated/completed: This is a state where the process completes with the execution part.
     
  • Zombie: This is a state where the process is terminated. The process consists of information after the termination as well.

Question 38: What are the various modes of vi editors?

Answer: VI stands for Visual Editor. It is a default text editor. There are three types of modes in the VI editor.

  • Regular mode/Command mode.
     
  • Insertion mode/Edit mode.
     
  • Replacement mode/Ex mode.

Question 39: What do you mean by Linux Directory Commands?

Answer: The five Linux directory commands which are used to work with directories and files are the following:

  • pwd: pwd is an abbreviation for print working directory. This is a command which is used for path display. $pwd is the syntax used for pwd.
     
  • cd: cd is an abbreviation for change directory. This is a command used to change the present working directory to the directory that we want to work on. $cd <path to new directory> is used as a syntax for cd.
     
  • Is: Is is an abbreviation for list. This is a command used to show the complete list of content of files and directories. $ls is used as a syntax for Is.
     
  • mkdir: mkdir is an abbreviation for make directory. This command allows users to create directories in Linux.  $ mkdir <name of new directory> is used as a syntax for mkdir.
     
  • rmdir: rmdir is an abbreviation for removing a directory. This command is used to remove or delete each directory that is specified on the command line.  $ rmdir <name of directory> is used as a syntax for rmdir.

Question 40: What are Process Management System Calls in Linux?

Answer: The process management system calls in Linux:

  • fork() system callIt is used to create a new process in Linux.
     
  • exec(): It is used to execute new processes in Linux.
     
  • wait(): It is used to wait for the process until the execution part is not done.
     
  • exit(): It is used to exit from the process.
     
  • getpid(): It is used to find the unique process id in Linux. 
     
  • getppid(): It is used to find the unique parent process id in Linux. 

Question 41: How do you compress and extract files in Linux using tar?

Answer: To compress files using the tar command:

tar -czvf archive.tar.gz /path/to/files
  • -c: Create a new archive.
  • -z: Compress using gzip.
  • -v: Verbose mode.
  • -f: Specify the file name.

To extract files from a tar.gz archive:

tar -xzvf archive.tar.gz

Question 42: How do you create a new user in Linux?

Answer: To create a new user, use the useradd command followed by the username. For example:

sudo useradd username

 

You can also set a password for the new user:

sudo passwd username

Question 43: What is LVM?

Answer: LVM (Logical Volume Manager) is a system for managing disk storage in a more flexible way than traditional partitioning. It allows resizing of partitions, combining multiple physical drives into a single logical volume, and taking snapshots.

Question 44: How do you monitor disk I/O in Linux?

Answer: You can monitor disk I/O using tools like iostat and iotop:

  • iostat: Displays CPU and I/O statistics.
  • iotop: Shows a real-time view of disk I/O usage by processes.

Question 45: What is cgroups?

Answer: cgroups (Control Groups) is a Linux kernel feature that allows you to allocate resources (CPU, memory, disk I/O, etc.) to processes or groups of processes.

Linux OS Internals Interview Questions

Question 46: What is the role of the Linux Kernel?

Answer: The Linux Kernel is the core component of the Linux OS that manages hardware resources like CPU, memory, and I/O devices. It provides essential services to applications through system calls and manages processes, memory, file systems, and hardware devices.

Question 47: What is a system call in Linux?

Answer: A system call is a mechanism that allows user-space applications to request services from the kernel. Examples include file manipulation (open, read, write), process control (fork, exec), and inter-process communication (pipe, shmget).

Question 48: What is the difference between user mode and kernel mode in Linux?

Answer:

  • User mode: The CPU runs user applications with restricted access to system resources.
  • Kernel mode: The CPU runs in privileged mode, allowing full access to system hardware and resources. Transitions between these modes happen via system calls.

Question 49: What are kernel modules, and how do you manage them?

Answer: Kernel modules are pieces of code that can be dynamically loaded and unloaded into the Linux kernel at runtime. They extend kernel functionality (e.g., device drivers).

  • Load module: insmod module_name.ko
  • Unload module: rmmod module_name
  • List modules: lsmod

Question 50: Explain process scheduling in the Linux kernel.

Answer: The Linux kernel uses the Completely Fair Scheduler (CFS), which distributes CPU time fairly among processes based on priority and workload. It supports real-time and normal processes, ensuring each process gets a fair share of CPU time.

Question 51: What is the difference between a process and a thread in Linux?

Answer:

  • Process: An independent program that runs in its own memory space with its own resources.
  • Thread: A lightweight execution unit within a process, sharing the process's memory and resources, making it easier to share data between threads.

Question 52: How does the Linux kernel handle memory management?

Answer: The Linux kernel handles memory through paging (splitting memory into pages), segmentation (splitting memory into logical divisions like code, data, and stack), and virtual memory (allowing processes to use more memory than physically available by swapping pages between RAM and disk).

Question 53: What is an inode in Linux?

Answer: An inode is a data structure that stores information about a file, such as file size, ownership, permissions, and data block pointers. It does not store the file name, which is managed separately in the directory structure.

Question 54: What is the purpose of the fork() system call?

Answer: The fork() system call creates a new process by duplicating the calling process. The child process gets its own PID but shares the same code and memory structure initially as the parent. It returns 0 to the child process and the child’s PID to the parent.

Question 55: How does the Linux kernel handle interrupts?

Answer: The kernel uses an Interrupt Request (IRQ) system. When a device needs CPU attention, it sends an interrupt. The kernel's interrupt handler responds to the request, processes the interrupt, and communicates with the device. After handling, the CPU resumes the previous task.

Linux Admin Interview Questions

Question 56: What is the purpose of the /etc/passwd file?

Answer: The /etc/passwd file is a critical system file in Linux that stores essential information about user accounts. Each line in the file represents a user account and contains fields separated by colons, including:

  • Username
  • Encrypted password (typically stored in /etc/shadow for security)
  • User ID (UID)
  • Group ID (GID)
  • User's full name or description
  • Home directory
  • Login shell

This file is used by various system utilities to manage user accounts and permissions.

Question 57: How do you check system resource usage in Linux?

Answer: There are several commands to check system resource usage in Linux:

  • top or htop: Provides a real-time, dynamic view of system processes and resource usage.
  • free: Displays information about system memory usage.
  • df: Shows disk space usage for mounted filesystems.
  • iostat: Reports CPU statistics and I/O statistics for devices and partitions.
  • vmstat: Reports information about processes, memory, paging, block I/O, and CPU activity.

Question 58: What is a symbolic link and how do you create one?

Answer: A symbolic link (also known as a symlink or soft link) is a special type of file that points to another file or directory. It's similar to a shortcut in Windows.

To create a symbolic link, use the ln command with the -s option:

ln -s target_path link_name

 

For example:

ln -s /path/to/original/file /path/to/symlink

Question 59: How do you find large files on a Linux system?

Answer: You can use the find command combined with sort to locate large files:

find /path/to/search -type f -size +100M -exec ls -lh {} \; | sort -k5 -rh

This command will:

  • Search for files larger than 100MB
  • List them with human-readable sizes
  • Sort them by size in descending order

Question 60: What is the purpose of the cron daemon?

Answer: The cron daemon is a time-based job scheduler in Unix-like operating systems. It enables users to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals. Common uses include:

  • Automating system maintenance tasks
  • Scheduling backups
  • Running periodic reports
  • Monitoring system health

Jobs are configured in crontab files, which specify the schedule and command to run.

Question 61: How do you check open ports on a Linux system?

Answer: To check open ports on a Linux system, you can use the following commands:

  • netstat -tuln: Shows all active listening ports
  • ss -tuln: A more modern alternative to netstat
  • lsof -i: Lists all network connections and the processes using them

For example:

sudo netstat -tuln | grep LISTEN

This will show all TCP and UDP ports in the LISTEN state.

Question 62: What is the purpose of the /etc/fstab file?

Answer: The /etc/fstab (file system table) file contains information about how disk partitions and other block devices should be mounted into the file system. It includes:

  • Device identifiers (UUID, device path)
  • Mount points
  • Filesystem types
  • Mount options
  • Dump and pass values for filesystem checks

This file is read by the system during boot to determine which filesystems to mount and how to mount them.

Question 63: How do you troubleshoot high CPU usage on a Linux server?

Answer: To troubleshoot high CPU usage:

  1. Use top or htop to identify which processes are consuming the most CPU.
  2. Check the load average with uptime to see if the system is overloaded.
  3. Use ps aux to get more detailed information about specific processes.
  4. Check system logs (/var/log/syslog or journalctl) for any errors or warnings.
  5. Use strace to trace system calls and signals for a specific process.
  6. If it's a web server, check the access logs for unusual traffic patterns.
  7. Consider using more specialized tools like perf for performance analysis if needed.

Question 64: What is SELinux and what are its modes?

Answer: SELinux (Security-Enhanced Linux) is a security architecture integrated into the Linux kernel that provides mandatory access control (MAC) system. It enforces security policies to restrict programs' access to system resources.

SELinux has three modes:

  1. Enforcing: SELinux policy is enforced. Security policy violations are prevented and logged.
  2. Permissive: SELinux policy is not enforced, but violations are logged. This is useful for troubleshooting.
  3. Disabled: SELinux is turned off completely.

You can check the current mode with getenforce and change it with setenforce (temporarily) or by editing /etc/selinux/config (permanently).

Question 65: How do you set up a basic firewall using iptables?

Answer: Here's a basic example of setting up a firewall using iptables:

# Flush existing rules
iptables -F

# Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# Allow loopback connections
iptables -A INPUT -i lo -j ACCEPT

# Allow established and related connections
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# Allow incoming SSH (adjust port if needed)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# Allow incoming HTTP and HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# Log dropped packets
iptables -A INPUT -j LOG --log-prefix "IPTables-Dropped: "

# Save rules (Debian/Ubuntu)
sudo iptables-save > /etc/iptables/rules.v4

This basic setup allows SSH, HTTP, and HTTPS traffic while blocking other incoming connections. Remember to adjust rules based on your specific needs and to use a persistent solution like iptables-persistent to ensure rules survive reboots.

Linux Troubleshooting Interview Questions

Question 66: How do you check disk space usage on a Linux system?

Answer: To check disk space usage, you can use the df command:

  • df -h: Shows disk usage in a human-readable format (GB, MB).
  • du -sh /path/to/directory: Displays disk usage for a specific directory.

Question 67: How can you troubleshoot high CPU usage on a Linux system?

Answer: Use the following tools to troubleshoot high CPU usage:

  • top: Provides a real-time view of running processes and their CPU usage.
  • htop: Similar to top, but with a more user-friendly interface.
  • ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu: Lists processes sorted by CPU usage.

Question 68: What command can you use to check for open ports and services?

Answer: Use the netstat or ss commands:

  • netstat -tuln: Lists all open ports and associated services.
  • ss -tuln: Shows open ports with more details and is faster than netstat.

Question 69: How do you check and free up memory on a Linux system?

Answer:

  • Use the free -h command to check memory usage in human-readable form.
  • Use top or htop to monitor memory usage by processes.
  • To free up memory, you can kill memory-intensive processes or use sync; echo 3 > /proc/sys/vm/drop_caches to drop the cache.

Question 70: How do you find large files on a Linux system that might be filling up disk space?

Answer: Use the find command to search for large files:

  • find / -type f -size +1G: Finds all files larger than 1GB in size. You can adjust the path and size parameter based on your requirement.

Question 71: How can you troubleshoot a system that won’t boot?

Answer:

  1. Check GRUB: Ensure the GRUB bootloader is loading correctly.
  2. Boot in recovery mode: Use recovery or rescue mode to access the system.
  3. Check logs: Check /var/log/syslog or /var/log/messages for error messages.
  4. Filesystem issues: Use fsck to check and repair filesystem corruption.

Question 72: How do you check for hardware issues on a Linux system?

Answer:

  • dmesg: Displays kernel ring buffer messages related to hardware and boot issues.
  • lshw: Lists detailed information about the hardware components of the system.
  • smartctl -a /dev/sda: Checks the health of hard drives using S.M.A.R.T. data.

Question 73: What are some ways to troubleshoot network connectivity issues in Linux?

Answer:

  1. Check interface status: Use ifconfig or ip a to check network interfaces.
  2. Ping test: Use ping <hostname/IP> to check network connectivity.
  3. Traceroute: Use traceroute <hostname/IP> to trace the route packets take.
  4. DNS issues: Use nslookup or dig to troubleshoot DNS resolution problems.

Question 74: How do you check the system logs for troubleshooting purposes?

Answer:

  • Use the journalctl command to view the system logs:
    • journalctl -xe: Shows the most recent critical errors.
    • journalctl -u <service-name>: Views logs specific to a service.
  • Alternatively, you can check the log files located in /var/log/, such as syslog, dmesg, and auth.log.

Question 75: How can you troubleshoot a slow system performance issue in Linux?

Answer:

  1. Check CPU usage: Use top or htop to monitor processes consuming CPU.
  2. Check memory usage: Use free -h and vmstat to monitor memory usage.
  3. Check I/O performance: Use iotop or iostat to monitor disk I/O issues.
  4. Review logs: Check logs in /var/log/ and use dmesg for hardware-related issues.

Linux Networking Interview Questions

Question 76: What is the purpose of the /etc/hosts file?

Answer: The /etc/hosts file is a plain text file used to map hostnames to IP addresses. It serves as a local DNS (Domain Name System) lookup mechanism. When a hostname needs to be resolved, the system checks this file before querying external DNS servers. Common uses include:

  • Quickly testing websites without DNS changes
  • Blocking access to specific websites by redirecting them to localhost
  • Creating shortcuts for frequently accessed machines on a local network

The file format is simple: each line contains an IP address followed by one or more hostnames.

Question 77: How do you check the IP address of a Linux system?

Answer: There are several ways to check the IP address on a Linux system:

  1. Using IP: ip -4 addr show 
    or for just the IP: ip addr show
  2. Using ifconfig (may need to be installed on some modern distributions): ifconfig
  3. Using hostname: hostname -I
  4. For the public IP address, you can use a command like: curl ifconfig.me

Question 78: What is the difference between TCP and UDP?

Answer: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are two of the main protocols in the Internet Protocol suite:

TCP:

  • Connection-oriented protocol
  • Guarantees delivery of data
  • Ensures data is delivered in order
  • Provides error-checking and recovery
  • Slower but more reliable
  • Used for applications requiring high reliability (e.g., web browsing, email)

UDP:

  • Connectionless protocol
  • Does not guarantee delivery of data
  • Data may arrive out of order
  • No error-checking or recovery
  • Faster but less reliable
  • Used for applications that prioritize speed over reliability (e.g., streaming, gaming)

Question 79: Explain the purpose of the netstat command.

Answer: The netstat command is a versatile networking tool used to display various network-related information:

  • Active network connections (both incoming and outgoing)
  • Routing tables
  • Network interface statistics
  • Masquerade connections
  • Multicast memberships

Common uses include:

  • Displaying all active connections: netstat -a
  • Showing only TCP or UDP connections: netstat -t or netstat -u
  • Displaying listening sockets: netstat -l
  • Showing the process ID and name of the program: netstat -p

Note that on many modern Linux systems, ss is recommended as a more efficient alternative to netstat.

Question 80: What is a subnet mask and how is it used?

Answer: A subnet mask is a 32-bit number used to divide an IP address into network and host portions. It's used in conjunction with an IP address to determine:

  • Which part of the IP address belongs to the network
  • Which part can be used for host addresses

For example, a common subnet mask is 255.255.255.0 (or /24 in CIDR notation). With this mask:

  • The first three octets (24 bits) represent the network
  • The last octet (8 bits) represents host addresses

Subnet masks are crucial for:

  • Defining network boundaries
  • Determining if two IP addresses are on the same network
  • Calculating the number of available host addresses in a network

Question 81: How do you set a static IP address in Linux?

Answer: Setting a static IP address depends on the Linux distribution and network management tool. Here's a general approach using netplan (common in Ubuntu):

1. Edit the netplan configuration file (e.g., /etc/netplan/01-netcfg.yaml):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]

2. Apply the changes:

sudo netplan apply

For systems using network scripts, you might edit /etc/sysconfig/network-scripts/ifcfg-eth0 (CentOS/RHEL) or /etc/network/interfaces (older Debian-based systems).

Question 82: What is NAT and how does it work?

Answer: NAT (Network Address Translation) is a method of remapping one IP address space into another by modifying network address information in the IP header of packets while they are in transit across a traffic routing device.

The main uses of NAT are:

  1. To enable multiple devices on a private network to access the internet using a single public IP address.
  2. To improve security by hiding the internal network structure from the outside world.

NAT typically works as follows:

  1. A device on the internal network sends a packet to an external destination.
  2. The NAT device (usually a router) receives the packet.
  3. It changes the source IP address from the internal private IP to its own public IP address.
  4. It keeps track of this translation in its NAT table.
  5. When a response comes back, the NAT device uses its table to determine which internal device should receive the packet, and translates the destination address accordingly.

Question 83: How do you troubleshoot network connectivity issues in Linux?

Answer: To troubleshoot network connectivity issues in Linux:

  1. Check physical connections (if applicable).
  2. Verify IP configuration: ip addr show or ifconfig
  3. Test local network: ping localhost
  4. Check DNS resolution: nslookup google.com or dig google.com
  5. Test gateway connectivity: ping your default gateway
  6. Check routing table: route -n or ip route show
  7. Test internet connectivity: ping 8.8.8.8 (Google's DNS server)
  8. Examine firewall rules: iptables -L or ufw status
  9. Check network services: systemctl status NetworkManager
  10. Analyze network traffic: tcpdump or wireshark
  11. Review system logs: journalctl -u NetworkManager

Question 84: What is the purpose of the traceroute command?

Answer: The traceroute command is used to trace the path that a packet takes from your computer to a specified destination. It shows:

  • The route taken by packets across an IP network
  • The time taken for each hop
  • Any packet loss along the way

This is useful for:

  • Identifying network bottlenecks
  • Diagnosing slow network connections
  • Verifying network routes
  • Detecting packet loss issues

Example usage:

traceroute google.com

This will show each hop (router) along the path to google.com, along with the time taken for each hop.

Question 85: Explain the difference between a switch and a router.

Answer: Switches and routers are both networking devices, but they operate at different layers of the OSI model and serve different purposes:

Switch:

  • Operates at Layer 2 (Data Link Layer) of the OSI model
  • Used to connect devices within the same network (LAN)
  • Forwards data based on MAC addresses
  • Creates separate collision domains for each port
  • Does not provide inter-network communication
  • Typically faster for internal network traffic

Router:

  • Operates at Layer 3 (Network Layer) of the OSI model
  • Used to connect different networks (e.g., LAN to WAN)
  • Forwards data based on IP addresses
  • Provides inter-network communication
  • Can implement network address translation (NAT)
  • Often includes basic firewall functionality
  • Typically used as the gateway between a local network and the internet

In simple terms, switches create networks, while routers connect networks together.

Linux Interview MCQs

Question 1: Which command is used to list all files in a directory, including hidden files?

a) ls
b) ls -a
c) ls -l
d) ls -lh
Answer: b) ls -a

Question 2: What is the command to check the current working directory in Linux?

a) pwd
b) cd
c) home
d) dir
Answer: a) pwd

Question 3: Which command is used to change file permissions in Linux?

a) chmod
b) chperm
c) chown
d) chattr
Answer: a) chmod

Question 4: What does the mkdir command do?

a) Creates a file
b) Deletes a directory
c) Creates a directory
d) Moves a file
Answer: c) Creates a directory

Question 5: How do you view the contents of a file in Linux?

a) cat
b) ls
c) touch
d) rm
Answer: a) cat

Question 6: Which command is used to display the running processes in Linux?

a) ps
b) top
c) jobs
d) All of the above
Answer: d) All of the above

Question 7: What is the use of the grep command in Linux?

a) To search for patterns within files
b) To display disk usage
c) To list users
d) To change file ownership
Answer: a) To search for patterns within files

Question 8: What does the df command display?

a) Free and used memory
b) Disk space usage
c) List of files in a directory
d) Network configuration
Answer: b) Disk space usage

Question 9: Which file contains user account information in Linux?

a) /etc/shadow
b) /etc/passwd
c) /etc/group
d) /etc/hostname
Answer: b) /etc/passwd

Question 10: What is the purpose of the kill command in Linux?

a) To stop a running process
b) To delete a file
c) To create a new user
d) To restart the system
Answer: a) To stop a running process

Frequently Asked Questions

Explain about Linux terminal.

A Unix-like operating system is Linux. The terminal offered by the Linux system is used to run all Linux/Unix commands. This terminal works in the same way as the command prompt in Windows. Commands in Linux/Unix are case-sensitive. All administrative operations can be completed through the terminal. Package installation, file manipulation, and user management are all included. The Linux terminal allows users to interact with it. The terminal displays the results of commands that the user has entered. Only when you press the Enter key does the entered command get executed.

Why is Linux better?

The fact that Linux is open-source software is its key selling point. The source code for Linux is open source and free to access, modify, and contribute to by anybody with the necessary expertise. One of the most appealing aspects of Linux is that there are no forced reboots or irritating update nags. And the fact that the majority of the software was updated concurrently with the system. IPtables provide an even higher level of security for Linux machines. This is a firewall that allows you to establish a more secure environment for running commands or connecting to the internet.

What are the disadvantages of Linux?

The disadvantages of Linux can be listed as follows: It isn't exactly user-friendly. As a result, it may be puzzling to freshers and In comparison to Windows, it contains fewer peripheral hardware drivers.

Conclusion

In this article, we have discussed Linux Interview Questions. Mastering Linux interview questions requires a solid understanding of both fundamental concepts and advanced topics related to Linux systems. By familiarizing yourself with common commands, troubleshooting techniques, and OS internals, you’ll be well-prepared for a range of interview scenarios.

Recommended Readings:

Live masterclass