Come prepared: Common & advanced Linux interview questions

Linux developer could be a high-earning gig, albeit Linux is a far less popular operating system than macOS and Windows (yet more secure and adaptable). It incorporates hundreds of components, concepts and peculiarities, so if you've got an interview with a potential employer coming up, it is better to be prepared. Those could also be questions of various levels, from beginner to advanced, command-related to network related, admin questions, DevOps questions, etc. For now, let's focus on Linux interview questions split in 2 groups - common and advanced. With answers of course.

15 most common Linux interview questions

1. Explain the difference between Unix and Linux

Unix is one of the first ever operating systems invented in 1969, and Linux sprung out of it when a Finnish student called Linus had made his own version. Since then, Linux is known to be portable, while Unix is not. Linux is based on graphical user interface, or command-line interface optionally, while Unix is command-line interface only. Linux is open source, Unix is proprietary belonging to AT&T, and thus, of course, the first one is free and the latter is paid. Also, Linux can be used on a variety of computers and devices, while Unix only on servers.

2. How different are Windows and Linux?

Linux is free and open source, while Windows is not free and owned by Microsoft. Windows is well known for security issues and vulnerability to malware attacks, Linux is much more secure. Microkernel is used by Windows, Linux uses monolithic kernel. For path separation Linux uses a forward slash, while Windows OS uses a backward slash.

3. Name and elaborate a bit on basic components of Linux

Essentially, Linux has five basic components. The first one is Kernel, which is at the core of the operating system, it acts as a link, or a bridge, between hardware and software. The second one is Shell - an interface for users to use a kernel. GUI is the third component, being a user interface allowing to control the OS. The fourth is Applications/Programs designed to perform a set of particular tasks/functions. The fifth and the final one is System Utilities which are software functions to manage the OS. Accompanied by 3 types of permissions (read, write, execute) users can work with the system and files.

4. What is Shell and how is it used?

Shell is one of the basic Linux components, and is basically an interface allowing the use of kernel in certain ways. Five shells are used in Linux: C Shell (csh) for spell checks, Korn Shell (ksh) for programming languages, Z Shell (ssh) for comments, startup files, file names, logins/logouts, etc; Bourne Again Shell (bash) as the default shell for the whole of Linux; and Friendly Interactive Shell (fish) for auto-suggests, web configurations, etc.

5. Hard and soft links, what are they and what is the difference?

Hard links act as copies of files. By accessing data in the original file, it ensures that data is still contained in the copy if the original is deleted. Soft links (or symbolic links) act as shortcuts to files and directories. They do not hold data from the original file. Hard links are also faster than soft links, and use less memory than soft links.

6. Can you elaborate on GUI and CLI?

GUI stands for ‘graphical user interface' and CLI is for ‘command line interface'. These are basically two main ways to interact with the Linux OS. GUI is an easier option for casual users familiar with windows, icons, buttons, etc. With CLI users can type in commands, and this is mostly for system admins or developers, since it uses fewer resources.

7. How many process states are there in Linux and what are they?

Similar to Windows and Mac, a process is a running program or service. There are five process states in Linux: Ready - already created and ready to run; Running - active/executed; Stopped - stopped running and terminated by the OS; Wait - waiting for user input; and Zombie - terminated yet still remaining in the process table.

8. Can you name a few basic Linux directory commands?

The main commands for the Linux directory are these: pwd - ‘present working directory' is being displayed; ls - directory contents are being displayed; cd - switch between different directories; mkdir - create a new directory; rmdir - delete an empty directory; rm - remove files.

9. Is it possible to run multiple commands via a single command?

Yes, it is possible. To do this, i.e. running multiple commands one after another in succession in a single command, we can either go with the semicolon (;), double ampersand (&&), or double straight slash (||) symbols. For example, X Y - to run commands X and Y regardless of the X result; X && Y - to run Y only if X goes through successfully; X || Y - to run Y only if X fails.

10. What is LILO and what is it for?

LILO, short for Linux Loader, is boot loading in Linux, meaning that it loads Linux OS into memory and starts the OS. LILO can be modified or configured differently, e.g. if the default state is incorrect. It handles tasks such as locating and starting the kernel, identifying applications, etc.

11. What is SAR and where are its logs stored?

This refers to the sar command, a way to gather and analyze system activity, e.g. CPU use, disk activity, network traffic. It is often used to troubleshoot performance issues and determine the source of high loads. SAR log files are saved in the /var/log/sa/sadd directory, ‘dd' being current day.

12. What is the password file and how can it be protected better?

It is the test file (/etc/passwd) where Linux stores user account details, including encrypted passwords. Obviously, this is a risk and to minimize it, we can use the shadow password format. It saves data in a regular file yet passwords are stored and marked as a single ‘X' character, so the actual password is not actually there. A secondary file (/etc/shadow) stores the encrypted password and some extra data such as expiration date, and is accessible via a root account only. The command for shadow password is pwconv.

13. Can you tell the name/path of the main system log?

In Linux it is /var/log/messages by default. It is the file containing all commands and scripts by a user, including system software logs, boot issues, messages to dmesg (system file with boot logs), etc.

14. What types of modes are you aware of in the visual editor?

The basic text editor in most Linux distributions is known as visual editor, or VI in short. Three basic modes are applied typically: Command/Regular mode (the default one to view and input instructions), Insertion/Edit mode (to edit text, to insert text into files, to delete text), and Replacement mode (to save file changes and execute commands).

15. Can a Linux computer be turned into a router for multiple computers?

Yes, a Linux PC can be converted into a router and act as an IP gateway for a multiple PCs network. The process is known as IP Masquerading, and it allows other devices on Linux to be connected to the Internet. There's how you do it: ensure a LAN Internet connection, ensure all computers run on Linux (to use the same DNS address), for IP forwarding use the echo 1 > /proc/sys/net/ipv4/ip_forward command, and finally run the /sbin/iptables command to set up rules for networking.

15 advanced Linux questions

16. How can you modify the window manager in Linux?

I would use the /.xinitrc file to change the window manager while logging to a certain window. Notably, the following command ought to be saved in this file: exec window manager; and then the file should be saved. As a result of this, a new window manager will be opened every time at the start. I would also list several typical commands to initiate desktop environments and window managers: startkde, gnome-session, blackbox, fvwm, wmaker, icewm.

17. In what way are ext2 and ext3 file systems different?

While the ext3 file system is an improved follow-up to ext2, the main difference is that ext3 supports journaling. In practice this shows when we face system crashes or irregular shutdowns. With ext2 each file should then be checked for consistency, while with ext3 journaling such a check is not necessary. Time to recover the ext3 system does not depend on the size or the number of files, rather on the journal size.

18. What is LVM and is it required?

LVM, or logical volume management, is a form, or an approach to manage disk storage space on Linux. The goal is volume management for multiple end users. The administrator is not obliged to allocate all disk space initially, as some space can be reserved for later. The admin can use LVM to segment logical data or combine partitions, that is basically move or resize storage as needed.

19. What is network bonding and what are its modes?

It is combining 2 or more networks into one interface. It can improve overall performance and increase bandwidth. There are multiple modes of network bonding in Linux:

Mode-0: a default one, with fail tolerance and load balancing options.

Mode-1: based on active backup policy, i.e. only one PC acts in the group, another one will act when other PCs fail.

Mode-2: connects a source Mac address and a destination Mac address to ensure fault tolerance.

Mode-3: based on broadcast policy, i.e. it transmits all data in the slave PC interface.

Mode-4: a dynamic mode, where aggregation groups are created with the same speed.

Mode-5: adaptive transmit load balancing mode, i.e. to balance the outgoing and the incoming traffic.

Mode-6: an adapting mode for load balancing.

20. What is the ls command for?

It is used when you need a list of all files and directories in the system. Without the arguments, it will enlist all the files in the current directory in alphabetical order. To get the list of files from the specific directory, specify the directory name in the syntax (ls /NAME). Similarly, to get the list of files from multiple directories, specify them separated by space (ls /NAME /NAME /NAME).

21. How to delete a file/directory from the system?

Use the rm command to delete a file or a directory specified in the command line, although be careful with the syntax. rm NAME - to remove a single file; rm NAME1, NAME2 - to remove multiple files; rm * .pdf - to remove all pdf files; rm -i NAME - to confirm before removal; rm -f NAME - to remove files without confirming.

22. What is a stateless Linux server?

It is a server without any existing states/connection to user information. In other words, when a user visits a web page, the server does not track user identity or actions on that page. In regards to performance, a stateless server is not bound to track and/or sync session data, thus a quicker response times. In case of system crash/lag, it does not impact a web page, since no data is actually stored on the server.

23. How to troubleshoot network connectivity issues?

There are several ways to do it, let's explore. First, check Internet connection, cables, etc. Second, check network configuration, i.e. whether it is correct and actually uses a correct IP address (ifconfig commands), whether the gateway is correct, etc. Third, check the firewall rules that may or may not block the connection for security reasons. Fourth, check the network interface (ifup/ifdown commands) - restart both the interface and the system.

24. What is the chmod command?

It is the command in Linux that can be used to manage/modify file permissions (read/write/execute). For example, to grant the ABC.sh script the write and execute permission we'd run the command: chmod u+wx ABC.sh. By the way, this command is not limited to read/write/execute permissions since there are multiple modes of running it.

25. Can you elaborate on RAID in Linux?

RAID, or ‘redundant arrays of independent disks', is a method of utilizing multiple disks instead of a single disk to increase performance. Basically, different disk drives are combined into a logical unit. There are RAID levels that can be configured: level 0 - or ‘striping', to split data into multiple disks; level 1 - ‘mirroring', to make a full copy of data on multiple disks; level 5 - to distribute data on multiple disks; level 6 - to distribute data using 2 sets of parity information; level 10 - level 0 and 1 combined to be able to create mirror disks.

26. What are the options to secure a Linux server?

To protect a server from data breach, malware or unauthorized access, there are multiple options. For instance, strong password, server updates, secured protocols (e.g. SSH) set to key-based authentication, intrusion detection system (IDS), firewall configuration to limit traffic, disabling unused services, regular backups and security audits, and last but not least, encryption of traffic.

27. How to set up a static IP using CLI?

To set a static IP address in Linux via the command-line interface, one has to make changes to the network config file. Its location may vary on different Linux distributions, typically it is /etc/network/interfaces. Open it in a text editor and modify the following:

iface eth0 inet 
static address 192.168.1.101
netmask 244.244.244.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.4.4.4

Then save changes and reboot the system.

28. Can you name and explain various types of mountpoints?

There are shared, slave, private, and unbindable mount points used in Linux. Shared mount points may be replicated many times, each copy would be exact. Slave mount points can also be replicated except information goes in one direction only - a slave point only gets mount and unmount events. Private mount points act as the name implies - points under it would not be displayed in replicated points. Finally, unbindable mount points, also private essentially, cannot be replicated via the bind flag or command.

29. Should auto-sign be used for Linux users or not and why?

Auto-sign could be useful as it reduces manual work when bootstrapping new nodes, and it is implemented via .example.com or even in the auto-sign configuration file. However, this could be risky because then a node could masquerade as another node and steal the information. Thus, if every node configuration is of importance to your network, you should not use auto-sign.

30. What is the role of continuous integration and continuous deployment in Linux DevOps?

CI and CD are critical for any Linux-based environments combining software development (Dev) and IT operations (Ops). CI implies integration of code modifications into a central single repository, and DevOps engineers apply automated tests to make sure new changes do not impact existing functions negatively. The overall goal is to detect errors/issues and decrease testing manually. CD is for automating and optimizing the deployment process. In Linux networks, DevOps use special tools, e.g. Docker, Ansible for CI and CD.