Linux Interview questions that are commonly asked in interviews

Posted by

Basic Questions

  1. What is Linux?
    • Answer: Linux is an open-source, Unix-like operating system kernel that is widely used in servers, desktops, and embedded systems.
  2. What is the Linux kernel?
    • Answer: The Linux kernel is the core part of the operating system that manages hardware resources, system processes, and enables software to interact with hardware.
  3. What is a Linux distribution?
    • Answer: A Linux distribution (distro) is a packaged version of the Linux operating system, including the kernel and a variety of software, tools, and a package management system (e.g., Ubuntu, CentOS, Debian).
  4. How do you check the current version of the kernel?
    • Answer: Use the uname -r command.
  5. What is a shell in Linux?
    • Answer: A shell is a command-line interpreter that provides a user interface for accessing the services of the kernel (e.g., Bash, Zsh).

Intermediate Questions

  1. What is the purpose of the /etc/fstab file?
    • Answer: The /etc/fstab file contains information about disk partitions and filesystems, specifying how they should be automatically mounted during boot.
  2. How do you change file permissions in Linux?
    • Answer: Use the chmod command to change file permissions.
  3. What is the difference between apt and yum?
    • Answer: apt is a package management tool used in Debian-based distributions, while yum is used in RedHat-based distributions.
  4. How do you view running processes in Linux?
    • Answer: Use the ps, top, or htop commands to view running processes.
  5. What is a symbolic link?
    • Answer: A symbolic link (symlink) is a type of file that points to another file or directory, allowing you to create shortcuts or references.

Advanced Questions

  1. Explain how you would troubleshoot a network issue in Linux.
    • Answer: Use tools like ping to check connectivity, ifconfig or ip to check interface configurations, netstat or ss to check active connections, and traceroute to track packet paths.
  2. What is crontab and how do you use it?
    • Answer: crontab is a configuration file that specifies scheduled tasks (cron jobs) to be run at specific times. Use crontab -e to edit, crontab -l to list, and crontab -r to remove cron jobs.
  3. What is SELinux?
    • Answer: Security-Enhanced Linux (SELinux) is a security module in the Linux kernel that provides a mechanism for supporting access control security policies.
  4. How do you monitor system performance in Linux?
    • Answer: Use commands like top, vmstat, iostat, free, sar, and tools like nmon, glances, or perf.
  5. What are inodes in Linux?
    • Answer: Inodes are data structures on a filesystem that store information about a file or directory, such as its size, owner, permissions, and disk location.

Scenario-Based Questions

  1. Describe how you would set up a web server on Linux.
    • Answer: Install a web server package (e.g., Apache or Nginx) using the package manager, configure the server settings in the configuration files, start and enable the service, and ensure proper firewall rules are set.
  2. How would you handle disk space issues on a Linux server?
    • Answer: Use commands like df and du to identify disk usage, clean up unnecessary files, compress large files, and consider adding more storage or resizing partitions.
  3. How do you secure a Linux server?
    • Answer: Implement strong passwords, disable root login over SSH, use SSH keys for authentication, keep the system updated, configure firewalls, enable SELinux or AppArmor, and regularly review security logs.
  4. What steps would you take to troubleshoot a slow-performing Linux system?
    • Answer: Check CPU and memory usage with top or htop, analyze disk I/O with iostat, check network activity with netstat, and review system logs in /var/log.
  5. How do you backup and restore data on a Linux server?
    • Answer: Use tools like rsync, tar, or dd for backups, and restore data using the same tools. Automate backups with cron jobs and ensure backups are stored securely.
  6. How would you configure RAID on a Linux server?
    • Answer: Use mdadm to create and manage RAID arrays, specify RAID level, configure the array, and update the /etc/mdadm/mdadm.conf file to ensure persistence.
  7. Explain how you would set up a firewall on a Linux server.
    • Answer: Use iptables or firewalld to configure firewall rules, define policies for incoming and outgoing traffic, and ensure the firewall service is enabled and running.
  8. How do you manage software packages in Linux?
    • Answer: Use package managers like apt for Debian-based distributions or yum/dnf for RedHat-based distributions to install, update, and remove software packages.
  9. Describe how you would configure a new user and set permissions in Linux.
    • Answer: Use useradd or adduser to create a new user, set a password with passwd, assign the user to groups with usermod, and set file permissions using chmod and chown.
  10. What is LVM and how do you use it?
    • Answer: Logical Volume Manager (LVM) allows for flexible disk management. Use pvcreate to create physical volumes, vgcreate to create volume groups, and lvcreate to create logical volumes.

Advanced Questions

  1. Explain how you would configure and use systemd for managing services.
    • Answer: systemd is a system and service manager for Linux. Use systemctl commands to start, stop, enable, and disable services. Create and edit unit files in /etc/systemd/system/ to define services and their dependencies.
  2. What is the purpose of the /proc filesystem and how is it used?
    • Answer: The /proc filesystem is a virtual filesystem that provides an interface to kernel data structures. It is used to access process information and system statistics, such as CPU and memory usage, in a hierarchical file structure.
  3. How do you handle kernel module management in Linux?
    • Answer: Use modprobe to add or remove modules, lsmod to list loaded modules, rmmod to remove modules, and configure module loading options in /etc/modprobe.d/.
  4. Describe the process of configuring and using SELinux in enforcing mode.
    • Answer: Set SELinux to enforcing mode by editing /etc/selinux/config or using setenforce 1. Use semanage and restorecon to manage and restore security contexts. Define policies with .te files and compile them with checkmodule and semodule_package.
  5. What are cgroups in Linux, and how do you use them?
    • Answer: Control Groups (cgroups) are a feature that limits, accounts for, and isolates resource usage (CPU, memory, disk I/O, etc.) of a collection of processes. Use cgcreate, cgset, and cgexec commands to create and manage cgroups.

Scenario-Based Questions

  1. How would you diagnose and resolve a high CPU usage issue on a Linux server?
    • Answer: Use top or htop to identify processes with high CPU usage. Investigate the cause by checking logs, reviewing recent changes, and profiling the application if necessary. Optimize or kill the offending processes and consider resource limits if needed.
  2. Explain how you would set up a high-availability cluster using Linux.
    • Answer: Use tools like Pacemaker and Corosync to manage cluster resources and services. Configure fencing devices for node isolation, set up a shared storage system like DRBD or a distributed filesystem, and ensure proper network configuration for redundancy.
  3. How do you implement disk quotas in Linux?
    • Answer: Enable disk quotas by editing /etc/fstab to include usrquota and grpquota options, remount the filesystem, and use quotacheck to create quota files. Set quotas with edquota and enforce them with quotaon.
  4. Describe how you would recover a Linux system that fails to boot.
    • Answer: Boot from a live CD or rescue mode. Check and repair filesystem errors with fsck, reconfigure the bootloader (GRUB) if needed, review and edit configuration files in /etc, and check kernel logs for errors.
  5. How would you secure a Linux server against unauthorized access?
    • Answer: Implement strong passwords and use SSH keys for authentication. Disable root login over SSH, configure firewalls with iptables or firewalld, use SELinux or AppArmor for access control, keep the system updated, and regularly review logs.
  6. Explain how you would set up a Linux server to act as a router.
    • Answer: Enable IP forwarding by editing /etc/sysctl.conf or using sysctl -w net.ipv4.ip_forward=1. Configure iptables or nftables for NAT and routing rules. Ensure network interfaces are properly configured for internal and external traffic.
  7. How do you automate tasks in Linux using cron and anacron?
    • Answer: Use crontab -e to edit cron jobs for periodic tasks and define their schedule with cron syntax. Use /etc/anacrontab to configure anacron for tasks that need to run on a non-fixed schedule or on systems that are not always on.
  8. What steps would you take to investigate a disk I/O bottleneck on a Linux system?
    • Answer: Use iostat, vmstat, and iotop to monitor disk I/O performance. Check for high usage processes, review filesystem performance, optimize applications accessing the disk, and consider hardware upgrades or additional disks if necessary.
  9. How would you set up and manage a software RAID array on a Linux server?
    • Answer: Use mdadm to create and manage RAID arrays. Configure the array with mdadm --create, monitor it with mdadm --detail, and ensure persistence by updating /etc/mdadm/mdadm.conf and creating an appropriate entry in /etc/fstab.
  10. Describe how you would secure network services on a Linux server.
    • Answer: Limit the exposure of services by configuring firewalls and using TCP wrappers. Disable unnecessary services, use TLS/SSL for encrypted communication, regularly update software, and use tools like fail2ban to protect against brute-force attacks.
  11. How do you configure and use LVM snapshots for backups?
    • Answer: Create LVM snapshots using lvcreate --snapshot, mount the snapshot, and perform backups from the mounted snapshot to avoid downtime. After backups, remove the snapshot with lvremove.
  12. Explain how you would configure a VPN server on Linux.
    • Answer: Install and configure a VPN solution like OpenVPN or WireGuard. Set up server and client configurations, manage keys and certificates, and configure firewall and routing rules to ensure secure communication.
  13. How would you set up centralized logging for multiple Linux servers?
    • Answer: Use rsyslog or syslog-ng to configure a centralized logging server. Set up client servers to forward logs to the central server using appropriate configurations in /etc/rsyslog.conf or /etc/syslog-ng/syslog-ng.conf.
  14. Describe how you would optimize the performance of a MySQL database running on Linux.
    • Answer: Tune MySQL configuration parameters in my.cnf, optimize queries and indexing, use tools like mysqltuner for recommendations, regularly analyze slow query logs, and consider hardware upgrades like SSDs for better performance.
  15. How do you configure and use iptables for firewall management?
    • Answer: Define firewall rules using iptables commands to accept, drop, or reject traffic based on criteria like source/destination IP, port, and protocol. Save the configuration with iptables-save and ensure rules are loaded at boot with appropriate init scripts or systemd services.
  16. Explain how you would set up and manage a Docker environment on Linux.
    • Answer: Install Docker, configure the Docker daemon, create and manage containers using docker commands, use Docker Compose for multi-container applications, and secure the Docker environment by controlling access to the Docker daemon.
  17. How do you use and manage system logs in Linux?
    • Answer: View system logs using journalctl for systemd systems and tail, less, or grep for log files in /var/log. Rotate logs using logrotate to manage log size and retention, and configure logging services like rsyslog or syslog-ng.
  18. Describe the process of patch management in Linux.
    • Answer: Regularly update the package repository metadata using apt-get update or yum check-update. Apply updates and patches using apt-get upgrade or yum update. Automate updates using cron jobs or tools like unattended-upgrades for Debian-based systems.
  19. How would you implement and manage disk encryption on a Linux system?
    • Answer: Use LUKS (Linux Unified Key Setup) for disk encryption. Create an encrypted partition with cryptsetup, open and format the partition, and configure /etc/crypttab and /etc/fstab to ensure the partition is mounted at boot.
  20. How do you ensure system integrity and detect unauthorized changes on a Linux server?
    • Answer: Use tools like AIDE (Advanced Intrusion Detection Environment) or Tripwire to create and monitor integrity databases. Regularly check for unauthorized changes and set up alerts for detected discrepancies.
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x