Interview

15 Linux OS Interview Questions and Answers

Prepare for your next technical interview with our comprehensive guide on Linux OS, featuring curated questions to enhance your understanding and skills.

Linux OS is a cornerstone of modern computing, powering everything from personal devices to enterprise servers and cloud infrastructure. Known for its stability, security, and flexibility, Linux is an essential skill for IT professionals, system administrators, and developers. Its open-source nature allows for extensive customization and optimization, making it a preferred choice for many organizations.

This guide offers a curated selection of interview questions designed to test and enhance your understanding of Linux OS. By working through these questions, you will gain deeper insights into Linux’s core concepts and practical applications, preparing you to confidently tackle technical interviews and demonstrate your expertise.

Linux OS Interview Questions and Answers

1. Describe the structure and purpose of the /etc directory.

The /etc directory in Linux is a central location for system configuration files, essential for the system’s operation. Key components include:

  • /etc/passwd: User account information.
  • /etc/fstab: Disk drives and partitions information.
  • /etc/hosts: Maps hostnames to IP addresses.
  • /etc/init.d/: Initialization scripts for services.
  • /etc/ssh/: SSH configuration files.

The structure is hierarchical, with subdirectories and files organized by function.

2. How would you change the ownership and permissions of a file?

In Linux, each file and directory has an owner and permissions that determine access. Use chown to change ownership and chmod to change permissions.

Example to change ownership:

chown new_owner filename

Example to change permissions:

chmod 755 filename

3. Explain how you would terminate a running process.

Terminating a running process in Linux can be done using commands like kill, pkill, and killall, which send signals to terminate processes.

Example:

# Terminate a process with a specific PID
kill <PID>

# Terminate all processes with a specific name
pkill <process_name>

# Terminate all instances of a process
killall <process_name>

4. What command would you use to install a package on a Debian-based system? (Include comparison with RPM-based systems)

To install a package on a Debian-based system, use apt-get or apt.

Example:

sudo apt-get install package_name

For RPM-based systems like Red Hat, use yum or dnf.

Example:

sudo yum install package_name

5. Which command would you use to check the current IP address of your machine?

To check the current IP address, use the ip command.

Example:

ip addr show

To filter for IPv4 addresses:

ip -4 addr show | grep inet

6. How would you check the available disk space on your system?

To check available disk space, use df for a summary of disk space and du for file space usage.

Example with df:

df -h

Example with du:

du -sh /path/to/directory

7. Where are system logs typically stored, and how would you view them?

System logs are typically stored in the /var/log directory. Use tools like cat, less, tail, and grep to view them.

Example to view the last few lines of syslog:

tail /var/log/syslog

To monitor in real-time:

tail -f /var/log/syslog

8. How do you add a new user to the system?

To add a new user, use the useradd command followed by passwd to set a password.

Example:

sudo useradd newusername
sudo passwd newusername

9. How would you schedule a daily backup using cron?

Cron is a job scheduler that allows scheduling of periodic tasks. To schedule a daily backup, edit the crontab file.

Example:

crontab -e

Add a line for a daily backup at 2 AM:

0 2 * * * /path/to/backup.sh

10. Describe how you would configure a static IP address on a network interface.

To configure a static IP address, edit network configuration files or use command-line tools. The method varies by distribution.

Example for Ubuntu using Netplan:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

Apply changes with:

sudo netplan apply

11. How do you create and manage logical volumes using LVM?

Logical Volume Manager (LVM) allows flexible disk management. To create and manage logical volumes:

  • Initialize Physical Volumes (PVs):
    bash pvcreate /dev/sda1 /dev/sda2
  • Create a Volume Group (VG):
    bash vgcreate my_volume_group /dev/sda1 /dev/sda2
  • Create a Logical Volume (LV):
    bash lvcreate -L 10G -n my_logical_volume my_volume_group
  • Format the Logical Volume:
    bash mkfs.ext4 /dev/my_volume_group/my_logical_volume
  • Mount the Logical Volume:
    bash mount /dev/my_volume_group/my_logical_volume /mnt
  • Resize the Logical Volume (if needed):
    bash lvresize -L +5G /dev/my_volume_group/my_logical_volume resize2fs /dev/my_volume_group/my_logical_volume

12. What steps would you take to troubleshoot a system that fails to boot?

To troubleshoot a system that fails to boot:

  • Check hardware connections.
  • Examine bootloader configuration.
  • Review system logs.
  • Boot into recovery mode if available.
  • Check filesystem integrity with fsck.
  • Reinstall bootloader if necessary.
  • Update kernel parameters if needed.

13. What are some best practices for securing a Linux server?

Securing a Linux server involves several practices:

  • Regular updates.
  • User management with strong password policies and SSH keys.
  • Firewall configuration.
  • Intrusion detection systems.
  • Log monitoring.
  • Disable unnecessary services.
  • Secure SSH configurations.
  • Set appropriate file permissions.
  • Backup and recovery plans.

14. How would you troubleshoot network connectivity issues on a Linux system?

To troubleshoot network connectivity issues:

1. Check network interface configuration with ifconfig or ip addr.
2. Verify connectivity using ping.
3. Check routing table with route or ip route.
4. Verify DNS resolution with nslookup or dig.
5. Inspect firewall rules with iptables or firewalld.
6. Check network services with netstat or ss.
7. Review system logs with dmesg, journalctl, or tail -f /var/log/syslog.
8. Use traceroute to trace packet paths.

15. How do you monitor and manage system resources using tools like top, htop, and vmstat?

Monitor and manage system resources using tools like top, htop, and vmstat.

  • top: Provides a dynamic view of processes, showing CPU and memory usage.
  • htop: An interactive process viewer with a user-friendly interface, offering additional features like scrolling and color-coded output.
  • vmstat: Reports on processes, memory, paging, block I/O, traps, and CPU activity, useful for identifying trends over time.
Previous

10 xUnit Interview Questions and Answers

Back to Interview
Next

10 Multithreading in iOS Interview Questions and Answers