If you're planning to land a job in the field of Linux, it's important to be well-prepared for the interview process. Linux is one of the most widely used operating systems. According to Fortune Business Insights, the global Linux market will reach $15.64 trillion by 2027.
A vast number of companies and organizations worldwide use it. Hence, it's essential to have a solid understanding of Linux concepts and principles.
To prepare for your Linux job interview, we've compiled a list of the top 60 Linux interview questions and answers for experienced professionals and beginners. These questions test your knowledge of Linux and help you showcase your skills to potential employers.
Read on to learn more about the Linux interview questions you can expect in 2023.
Linux Interview Questions and Answers for Freshers
1. What is Linux, and how is it different from other operating systems?
Linux is an open-source operating system that is based on Unix. It differs from other operating systems because it is free to use, modify, and distribute. Also, Linux has a modular design, which allows users to customize the system to their specific needs.
2. What is the shell, and how does it work in Linux?
The shell is a command-line interface that allows users to interact with the Linux operating system. It interprets the commands entered by the user and executes them. The most commonly used shell in Linux is the Bash shell.
3. What is the root user in Linux, and why is it important?
The root user is the superuser in Linux, who has complete control over the system. It is important because many system-level operations require root privileges, such as installing software, modifying system files, and creating new user accounts.
4. How do you install software in Linux?
The software can be installed in Linux using package managers like Yum or apt-get. These package managers automate the software installation process and take care of dependencies.
5. How do you create a new user account in Linux?
A new user account can be created in Linux using the useradd command. For example, to create a new user named "John," you can use the command
useradd john
6. What is SSH, and how is it used in Linux?
SSH (Secure Shell) is a network protocol that allows secure communication between two networked devices. In Linux, it is commonly used to log into a remote machine and execute commands as if you were sitting in front of it.
7. What is a firewall in Linux, and how does it work?
A firewall is a network security system that monitors and controls incoming and outgoing network traffic. In Linux, the most commonly used firewall is iptables, which allows you to define incoming and outgoing traffic rules.
8. What is a cron job, and how does it work in Linux?
A cron job is a scheduled task executed automatically at a specified time or interval. In Linux, it is commonly used for tasks like backing up data, running system maintenance tasks and sending email notifications.
9. What is a symbolic link in Linux, and how is it created?
A symbolic link is a special type of file that acts as a pointer to another file or directory. It is created using the ln command with the -s option. For example, to create a symbolic link named "link" to a file named "file.txt," you can use the command "ln -s file.txt link."
10. What is the difference between hard and symbolic links in Linux?
A hard link is a link to an inode, which is a data structure that stores information about a file. It points directly to the file's data; any changes made to the original file are reflected in the hard link. On the other hand, a symbolic link is a link to a file's name. It points to the file's name, and any changes made to the original file do not affect the symbolic link.
11. Explain the steps to save a file in Linux.
To save a file in Linux, we can use any text editor like Nano, Vim, or Emacs. Here are the general steps to save a file using Nano editor:
- Open the file in the Nano editor by typing
nano filename
in the terminal, where the filename is the file name you want to edit. - Edit the contents of the file as required.
- Once you finish the changes, press Ctrl+O to save the file. This will prompt you to enter a filename if you haven't specified one already.
- Enter the filename and press Enter to save the file.
- Finally, press Ctrl+X to exit the Nano editor.
12. What are the types of shells in Linux?
There are several types of shells available in Linux, including:
- Bash (Bourne-Again SHell) - This is the most widely used shell in Linux and is the default shell in most Linux distributions.
- Korn Shell (ksh) - This is a powerful shell that is compatible with both the Bourne shell (sh) and the C shell (csh).
- C Shell (csh) - This shell is designed for interactive use and has a syntax that is similar to the C programming language.
- Z Shell (zsh) - This shell is similar to Bash but includes additional features such as better file name completion and spelling correction.
- Fish Shell (fish) - This shell emphasizes user-friendliness and ease of use. It includes features such as auto-suggestions and syntax highlighting.
13. What is the Linux kernel? Explain in brief.
The Linux kernel is like the heart of the Linux operating system. It manages how different computer parts work together, like the CPU, memory, and devices like a keyboard or a mouse.
It's open-source software created and improved by many people worldwide, and it's free to use and modify. The kernel is designed to be customizable to work well on different types of computers and for different purposes.
14. What do you mean by LILO?
LILO stands for "LInux LOader" and is a boot loader for Linux operating systems. It loads the Linux kernel into memory and starts the operating system. When a computer starts up, it searches for a bootloader to load the operating system. LILO is one of the boot loaders that can start Linux. It is installed on the computer's hard drive and loads the kernel from a specified location on the disk.
15. What are some alternatives to LILO?
Some modern alternatives to LILO as a boot loader for Linux are:
- GRUB (Grand Unified Bootloader): A widely used bootloader for Linux and other operating systems. It is highly configurable and supports various file systems and hardware configurations.
- GRUB2: The successor to GRUB and is now the default boot loader for most Linux distributions. It has more advanced features than its predecessor.
- SYSLINUX: A lightweight boot loader often booting Linux from USB drives or other removable media. It supports a wide range of file systems and hardware configurations.
- systemd-boot: A boot loader part of the systemd system and service manager. It is designed to be fast and lightweight and is often used on systems that use systemd as their init system.
Linux Admin Interview Questions and Answers for Experienced Employees
16. What is a runlevel in Linux?
A runlevel is a specific operating mode in a Linux system that determines which services and daemons should be running. The runlevel is identified by a number from 0 to 6, with each runlevel corresponding to a different system state.
- Runlevel 0: system shutdown state
- Runlevel 1: single-user mode
- Runlevel 2: multi-user mode without networking
- Runlevel 3: multi-user mode with networking
- Rrunlevel 4: not used
- Runlevel 5: Multi-user mode with GUI
- Runlevel 6: system reboot state.
17. How do you check the system uptime in Linux?
To check the system uptime in Linux, you can use the "uptime" command in the terminal. This command will display the current time, how long the system has been running, how many users are currently logged in, and the system's load average.
18. How do you add a new user account in Linux?
To add a new user account in Linux, you can use the "useradd" command in the terminal. For example, to create a new user account named "john," you can use the command "sudo useradd john." This will create a new user account with default settings. To set a password for the new user, you can use the
passwd
command.
19. What is SSH, and how do you use it?
SSH (Secure Shell) is a network protocol used to communicate between a client and a server securely. It provides an encrypted connection between two computers over an insecure network like the Internet.
To use SSH, you must have an SSH client installed on your computer and an SSH server running on the remote computer you want to connect to. You can then use the SSH client to connect to the remote server by providing the server's IP address or hostname and your login credentials.
20. How do you check the available disk space in Linux?
To check the available disk space in Linux, you can use the
df
command in the terminal. This command displays the amount of disk space used and available on all mounted file systems.
21. How do you mount a file system in Linux?
You can use the
mount
command in the terminal to mount a file system in Linux. For example, to mount a file system located on the device /dev/sdb1 to the directory /mnt/mydisk, you can use the commandsudo mount /dev/sdb1 /mnt/mydisk
22. What is the purpose of the "sudo" command in Linux?
The
sudo
command in Linux allows a user to execute a command with elevated privileges, typically as the root user. This command is often used to perform system administration tasks that require root-level access.
23. How do you check the system logs in Linux?
You can use the
journalctl
command in the terminal to check the system logs in Linux. This command displays the system logs in real time and allows you to filter the logs by date, time, severity, or other criteria.
24. How do you configure a network interface in Linux?
To configure a network interface in Linux, you can use the ifconfig
command or the ip
command in the terminal. For example, to set the IP address of the eth0 interface to 192.168.1.10, you can use the command sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0
25. Why is VI Editor used in Linux over other editors?
The VI editor has several advantages over other editors. Here are some of the main advantages of using Vi editor:
- Speed: VI editor is lightweight and can handle large files quickly and efficiently.
- Portability: Vi editor is available on almost all Unix and Linux systems, making it a very portable editor.
- Customization: Vi editor is highly customizable and can be customized with plugins and scripts to add additional features and functionality.
- Keyboard Shortcuts: Vi editor relies heavily on keyboard shortcuts, making it faster and more efficient than editors relying on mouse interactions.
- Command Line Integration: Vi editor integrates well with the command line, allowing users to run shell commands directly from the editor.
26. How do you check the default route and routing table?
The default route and routing table are checked through the following commands:
$ route-n
$ nestat-rn
$ ip
27. What are some common default ports and their associated services in Linux?
Common default ports and their associate services are:
Port Number | Service |
---|---|
22 | SSH |
80 | HTTP |
443 | HTTPS |
25 | SMTP |
110 | POP3 |
143 | IMAP |
3306 | MySQL Database |
5432 | PostgreSQL |
28. What is the common shortcut for logging out of the system in Linux?
The most common shortcut for logging out of the system is the
Ctrl + Alt + Del
key combination. This will create a dialog box with options to shut down, restart, or log out of the current session.
29. What are some special features of the root account?
Here are some special features of the root account in Linux:
- Administrative Privileges: The root account has administrative privileges, which means it can perform any task on the system, including modifying system files, installing and removing software, and creating and deleting user accounts.
- Full Access to the File System: The root account has full access to the entire file system, including all files and directories. This means the root user can read, write, and execute any file on the system.
- Ability to Kill Processes: The root account can kill any process on the system, including system processes. This can be useful for troubleshooting or if a process is causing problems.
- Ability to Change Permissions: The root account can change the permissions of any file or directory on the system. This can be useful for granting or revoking access to certain files or directories.
- Access to System Settings: The root account has access to all system settings and can modify them as needed. This can include network settings, system time and date, and other system-wide settings.
30. What are some common process management system calls in Linux?
Some common process management system calls in Linux:
- fork(): This system call creates a new process by duplicating the current process. The new process, the child process, is an exact copy of the parent process except for a few attributes.
- wait(): This system call suspends the execution of the current process until one of its child processes exits. It also allows the parent process to retrieve the exit status of the child process.
- getpid(): This system call returns the process ID (PID) of the current process.
- getppid(): This system call returns the PID of the parent process of the current process.
- nice(): This system call sets the priority of a process. A higher priority means the process will be scheduled more often, while a lower priority means the process will be scheduled less often.
- setuid() and setgid(): This system calls to change a process's user and group IDs.
Linux Networking Interview Questions and Answers (Experienced)
31. What is the difference between TCP and UDP protocols?
TCP (Transmission Control Protocol) provides reliable, ordered, and error-checked delivery of data, whereas UDP (User Datagram Protocol) does not guarantee reliable data delivery and is connectionless.
TCP | UDP |
---|---|
Transmission Control Protocol | User Datagram Protocol |
Connection-oriented protocol | Connectionless protocol |
Provides reliable data transfer with error checking and retransmission | Provides fast, lightweight data transfer without error checking or retransmission |
Uses sequencing and acknowledgement to ensure data integrity | Does not use sequencing or acknowledgement |
Provides flow control and congestion control to manage network traffic | Does not provide flow control or congestion control |
Slower than UDP due to overhead of error checking and sequencing | Faster than TCP due to lack of error checking and sequencing |
32. How can you configure a static IP address in Linux?
You can edit the network configuration file (/etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-eth0) and specify the static IP address.
33. What is the function of the cat command in Linux?
The
cat
command in Linux is a utility that allows you to concatenate and display files. It can be used to display the contents of a file on the terminal or to combine multiple files and display the output. The syntax of the command is:cat [options] [file(s)]
Some of the commonly used options of the cat
command are:
-n
: displays line numbers in the output-b
: displays line numbers for non-blank lines only-s
: squeezes multiple blank lines into a single blank line-A
: displays non-printing characters like tabs and newlines as visible characters
For example, to display the contents of a file named "file.txt" on the terminal, you can use the following command: cat file.txt
34. How do you change file permissions over a network in Linux?
To change file permissions over a network in Linux:
- Connect to the remote system using SSH or other remote access method.
- Use the
chmod
command followed by permission settings and file name. - Permission settings can be represented in three-digit octal numbers or symbolic notation.
- Verify the changes using the "ls -l" command.
Example: chmod 644 file.txt
sets read and write permission for the owner and read-only permission for the group and others.
35. How does swap space help in Linux networking?
Swap space helps in Linux networking in scenarios such as
- memory-intensive applications
- virtualized environments
- network file servers
In these cases, swap space can help prevent system crashes due to out-of-memory errors and handle the memory demands of virtual machines and network file servers.
36. What is a socket in Linux networking?
A socket is an endpoint for communication between two processes over a network. It is identified by an IP address and a port number.
37. What is the difference between TCP and UDP?
TCP is a connection-oriented protocol that provides reliable, ordered delivery of data, while UDP is a connectionless protocol that provides unreliable, unordered data delivery.
38. What is a subnet mask, and how does it work?
A subnet mask is a 32-bit number used to identify the network and host portions of an IP address. It is used with the IP address to determine the network ID and the host ID of a given network.
39. How do you troubleshoot network connectivity issues in Linux?
Troubleshooting network connectivity issues in Linux involves checking network configuration settings, verifying network connectivity with ping and traceroute, checking firewall settings, and examining system logs for errors.
40. What is DHCP, and how does it work?
DHCP (Dynamic Host Configuration Protocol) is a network protocol used to automatically assign IP addresses and other network configuration settings to devices on a network. It works by leasing IP addresses to devices for a specific period of time, allowing for efficient management of IP addresses on a network.
41. What is the easiest way to connect to a remote service through ssh
in Linux?
The easiest way to connect to a remote service through SSH in Linux is by using the
ssh
command from the terminal. Here are the basic steps to connect to a remote service:
a. Open the terminal on your local Linux machine.
b. Type ssh
followed by the username and IP address or domain name of the remote machine. For example: ssh username@remoteIPaddress
c. Press enter and enter the password when prompted.
d. Once connected, you can run commands on the remote machine as if you were logged in locally.
If you need to connect to a specific port, specify it using the
-p
option followed by the port number. For example:ssh username@remoteIPaddress -p 1234
To make the process even easier, you can set up SSH keys so that you don't need to enter the password every time you connect to the remote machine.
42. What is a VLAN in Linux networking, and how does it work?
A VLAN (Virtual Local Area Network) is a logical group of devices on a network. They are configured to communicate with each other as if they are on the same physical network, even if they are located on different switches or routers.
VLANs are created by configuring network switches to assign ports to a specific VLAN ID. This allows for greater network segmentation and control over network traffic.
43. How do you configure network bonding in Linux?
Network bonding, also known as link aggregation, is a technique used to combine multiple network interfaces into a single logical interface for increased bandwidth and redundancy.
Network bonding can be configured in Linux using the "bonding" kernel module and the
ifenslave
package. The process involves creating a bonding interface, configuring the network interfaces to be bonded, and setting the bonding mode and options.
44. What is a bridge in Linux networking, and how is it different from a router?
A bridge is a network device connecting multiple network segments and passing data between them. It operates at the data link layer of the OSI model and uses MAC addresses to forward traffic between segments.
Conversely, a router operates at the network layer of the OSI model and uses IP addresses to route traffic between networks.
While both devices can connect multiple networks, a bridge is typically used within a single network or LAN, while a router connects different networks or WANs.
Router | Bridge |
---|---|
Operates at the network layer (Layer 3) | Operates at the data link layer (Layer 2) |
Uses IP addresses to route packets between networks | Forwards packets based on MAC addresses within a single network |
Can connect multiple networks together | Connects segments of the same network together |
Performs packet filtering and network address translation (NAT) | Does not perform packet filtering or NAT |
May have multiple interfaces, each with its own IP address | Typically has a single interface and does not have an IP address |
Can perform Quality of Service (QoS) and traffic shaping | Does not perform QoS or traffic shaping |
45. How do you configure a static IP address in Linux, and what is the benefit of using a static IP over a dynamic IP?
A static IP address can be configured in Linux by editing the network configuration file (usually located at /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-eth0) and setting the IP address, netmask, gateway, and DNS servers.
A static IP address provides a fixed address for a device on the network, which can be useful for services that require a consistent IP address, such as a web server or DNS server.
On the other hand, a dynamic IP address is assigned automatically by a DHCP server and can change over time. While dynamic IP addresses are more convenient for end-user devices, static IP addresses are more reliable and predictable for network services.
Dynamic IP | Static IP |
---|---|
Assigned by DHCP server automatically | Assigned manually by network administrator |
Can change periodically depending on DHCP lease time | Stays the same until manually changed |
May require configuration or setup of DHCP client software | Requires manual configuration of network settings |
May experience interruptions if DHCP server is unavailable or lease expires | Provides continuous network connectivity |
Suitable for home networks or small businesses with limited devices and network traffic | Suitable for large businesses or organizations with many devices and heavy network traffic |
Provides less control over network configurations | Provides more control over network configurations |
Linux Technical and Command-based Interview Questions and Answers (Beginner & Experienced)
46. What are 5 important use cases of the Linux operating system?
Linux has a wide range of use cases due to its versatility, stability, security, and flexibility. Here are some common use cases of Linux:
- Web servers: Linux is the most widely used operating system, with over 70% of websites running on Linux-based servers. Some popular web servers running on Linux: Apache, Nginx, and Node.js
- Cloud computing: Due to its ability to handle high traffic, scalability, and reliability, Linux is preferable for cloud computing. Popular cloud platforms based on Linux: Amazon Web Services, Google Cloud Platform, and Microsoft Azure
- Mobile devices: Linux-based operating systems like Android and Ubuntu Touch power millions of smartphones, tablets, and other mobile devices.
- Supercomputers: Linux is the dominant operating system for supercomputers due to its ability to handle massive data processing and parallel computing.
- Internet of Things (IoT): Linux is widely used in IoT devices due to its small footprint, low power consumption, and flexibility.
47. What are some differences between Linux and Unix?
Property | Linux | Unix |
---|---|---|
Licensing | Open-source | Proprietary |
Development | Community-based | Company-based |
Cost | Typically free or low-cost | Requires license and can be expensive |
Kernel | Monolithic | Hybrid or Microkernel |
Commands | GNU commands | BSD commands |
File System | Ext4, XFS, Btrfs, etc. | UFS, JFS, ZFS, etc. |
Hardware Support | Supports a wide range of hardware | Limited hardware support |
System Administration | Typically managed using command line interface | Typically managed using graphical user interface |
Commercial Support | Available from vendors like Red Hat and SUSE | Available from Unix vendors like IBM and Oracle |
48. Name 2 properties of Linux system utilities
Here are two properties of Linux system utilities:
-
Modular design: Linux system utilities are designed to be modular, meaning they can be used independently or combined with other utilities to perform more complex tasks. This modular design makes Linux utilities flexible and adaptable to various use cases.
-
Command-line interface: Many Linux system utilities are designed to be used via a command-line interface allowing greater control and precision in managing the system. While some utilities also have graphical user interfaces (GUI), system administrators and power users often prefer the CLI for its speed and efficiency.
49. What are some best practices for maintaining security?
Some of the best practices for maintaining security in Linux include:
- Regularly reviewing and updating security policies and procedures
- Conducting regular security training and awareness programs for users and administrators
- Implementing a system for incident response and disaster recovery
- Regularly testing the system for vulnerabilities and weaknesses
- Staying informed about new security threats and vulnerabilities
50. How is disk space managed in Linux? What are some tools and techniques that can be used?
To manage disk space in Linux, you can use several tools and techniques such as:
df
command: Shows the amount of free and used disk space on the file systemdu
command: Shows the disk usage of a file or directoryncdu
command: Provides an interactive interface for exploring disk usage- Removing unnecessary files and directories
- Archiving and compressing large files
- Mounting additional storage devices or expanding existing storage
51. What common package management tasks can be performed with the apt-get
command?
Some common package management tasks that can be performed with the apt-get command include:
- Installing packages:
apt-get install
- Removing packages:
apt-get remove
- Updating package lists:
apt-get update
- Upgrading packages:
apt-get upgrade
- Cleaning up package files:
apt-get autoclean
andapt-get autoremove
52. What common networking tasks can be performed with the ip
command?
Some common networking tasks that can be performed with the ip command include:
- Configuring network interfaces:
ip address add
andip address del
- Configuring routing tables:
ip route add
andip route del
- Configuring network namespaces:
ip netns add
andip netns del
- Configuring VLANs:
ip link add link
andip link delete
53. Explain the chown
command.
The chown
command in Linux changes the ownership of files and directories. Ownership refers to the user and group assigned to a file or directory.
The basic syntax of the chown
command is as follows:
chown [OPTIONS] [OWNER][:GROUP] FILE…
Here are the 4 components of the chown command:
OPTIONS
: This is an optional parameter. It allows you to specify additional options for the chown command.OWNER
: This parameter specifies the user who should be the new owner of the file or directory. You can specify the new owner's username or UID (user ID).GROUP
: This parameter specifies the group that should be the new group owner of the file or directory. You can specify the new group owner's group name or GID (group ID).FILE
: This parameter specifies the file or directory whose ownership you want to change.
54. What is the find
command used for?
The
find
command searches for files and directories in a directory hierarchy. It can search based on various criteria, such as file name, type, size, and more.
55. What is the curl
command used for?
The
curl
command transfers data from or to a server using various protocols, such as HTTP, FTP, and SMTP. It can be used to download, upload, and test web services.
56. What is the ping
command used for?
The
ping
command tests the connectivity between two hosts on a network. It sends ICMP echo requests to the target host and waits for ICMP echo replies to confirm the connectivity.
57. What is the top
command used for?
The
top
command displays real-time information about running processes on a Linux system. It shows the system resource usage, such as CPU, memory, and disk usage, and the list of currently running processes.
58. What is the tar
command used for?
The
tar
command creates, manipulates, and extracts tar archives. A tar archive is a collection of files and directories compressed into a single file.
59. What is the sed
command used for?
The
sed
command performs text manipulation on a file or a data stream. It can find and replace text, delete lines, insert text, and more.
60. What is the mkdir
command used for?
The
mkdir
command is used to create a new directory.
Moving Ahead
The demand for Linux professionals grows as Linux continues to be one of the most used operating systems. Hence, candidates need to be well-prepared for the interview process. This article has provided a glimpse into some of the common and unique Linux interview questions that candidates can expect in 2023.
By practicing these questions, candidates can expect higher chances of success and stand out in the highly competitive job market. Regardless of being a beginner or an experienced Linux user, mastering these interview questions can help you demonstrate your expertise in Linux. Show off your technical skills, knowledge, and passion for Linux, and pave the way for a successful career in the field.