Top 50 interview questions for Linux, covering essential topics and concepts:
### Basic Linux Concepts
1. **What is Linux, and how does it differ from Unix?**
- Linux is an open-source, Unix-like operating system. Unlike Unix, which is proprietary, Linux is
freely available and developed collaboratively.
2. **What are the key components of the Linux operating system?**
- The key components include the Linux kernel, shell, file system, and various utilities and
applications.
3. **What is the Linux kernel?**
- The kernel is the core of the operating system that manages hardware, system resources, and
communication between software and hardware.
4. **How does the Linux file system hierarchy work?**
- Linux uses a hierarchical file system starting from the root directory (`/`), with various
subdirectories for system files, user files, and configuration files.
5. **Explain the difference between a file and a directory in Linux.**
- A file is a collection of data stored on disk, while a directory is a container that holds files and
other directories.
### File and Directory Management
6. **How do you list files and directories in Linux?**
- Use the `ls` command.
7. **How do you create a new directory in Linux?**
- Use the `mkdir` command.
8. **How do you remove a file or directory in Linux?**
- Use the `rm` command for files and `rm -r` for directories.
9. **What command would you use to copy files in Linux?**
- Use the `cp` command.
10. **How do you change file permissions in Linux?**
- Use the `chmod` command.
### Process Management
11. **How do you view running processes in Linux?**
- Use the `ps` command or `top` command.
12. **How do you kill a process in Linux?**
- Use the `kill` command followed by the PID.
13. **What is the difference between `kill` and `killall`?**
- `kill` targets a specific PID, while `killall` targets processes by name.
14. **How do you schedule tasks to run at a specific time in Linux?**
- Use `cron` and `crontab`.
15. **What is `cron`, and how do you use it?**
- `cron` is a time-based job scheduler. Use `crontab -e` to edit scheduled jobs.
### System Monitoring and Performance
16. **How do you check disk space usage in Linux?**
- Use the `df` command.
17. **How do you check memory usage in Linux?**
- Use the `free` command.
18. **How do you monitor network usage in Linux?**
- Use `iftop` or `netstat`.
19. **What is the `top` command, and what information does it provide?**
- `top` displays real-time system processes and resource usage.
20. **How do you check system logs in Linux?**
- Use the `dmesg` command or check files in `/var/log`.
### Networking
21. **How do you check the IP address of your Linux machine?**
- Use the `ip addr` or `ifconfig` command.
22. **How do you configure a static IP address in Linux?**
- Edit network configuration files such as `/etc/network/interfaces` or use `nmcli` for
NetworkManager.
23. **What is the `ping` command used for?**
- `ping` checks network connectivity to another host.
24. **How do you check open ports on your Linux system?**
- Use the `netstat` or `ss` command.
25. **What is the `traceroute` command used for?**
- `traceroute` tracks the route packets take to a network host.
### Package Management
26. **What package management systems are available in Linux distributions?**
- Examples include `apt` (Debian-based), `yum` (Red Hat-based), and `zypper` (openSUSE).
27. **How do you install a new package using `apt`?**
- Use `apt install package-name`.
28. **How do you update all installed packages using `yum`?**
- Use `yum update`.
29. **What is the `rpm` command used for?**
- `rpm` manages RPM packages (install, query, remove).
30. **How do you search for a package in Linux?**
- Use `apt search` or `yum search`.
### User and Group Management
31. **How do you create a new user in Linux?**
- Use the `useradd` command.
32. **How do you add a user to a group?**
- Use the `usermod -aG group-name user-name` command.
33. **How do you delete a user in Linux?**
- Use the `userdel` command.
34. **What is the `passwd` command used for?**
- `passwd` changes or sets user passwords.
35. **How do you list all users in Linux?**
- Check the `/etc/passwd` file or use `cut -d: -f1 /etc/passwd`.
### File System and Storage
36. **What is the `mount` command used for?**
- `mount` attaches file systems to the directory tree.
37. **How do you create and format a new partition in Linux?**
- Use `fdisk` or `parted` to create partitions and `mkfs` to format them.
38. **How do you resize a partition in Linux?**
- Use `resize2fs` for ext filesystems and `lvresize` for LVM.
39. **What is the `lsblk` command used for?**
- `lsblk` lists information about block devices.
40. **How do you check the health of a disk in Linux?**
- Use `smartctl` from the `smartmontools` package.
### Security
41. **How do you set up a basic firewall in Linux?**
- Use `iptables` or `firewalld`.
42. **How do you configure SSH key-based authentication?**
- Generate keys with `ssh-keygen` and copy the public key to `~/.ssh/authorized_keys` on the
remote server.
43. **What is `fail2ban`, and how is it used?**
- `fail2ban` is a tool to prevent brute-force attacks by blocking IPs with too many failed login
attempts.
44. **How do you check for failed login attempts in Linux?**
- Check logs in `/var/log/auth.log` or `/var/log/secure`.
45. **What is SELinux, and how does it work?**
- SELinux enforces security policies by restricting program capabilities based on security labels.
### Advanced Topics
46. **What is Docker, and how does it integrate with Linux?**
- Docker is a containerization platform that uses Linux features such as cgroups and namespaces to
isolate applications.
47. **How do you manage Docker containers and images in Linux?**
- Use `docker` commands such as `docker run`, `docker ps`, `docker pull`, and `docker build`.
48. **What is Kubernetes, and how does it relate to Linux?**
- Kubernetes is a container orchestration platform that manages Docker containers across a cluster
of Linux nodes.
49. **How do you create and manage systemd services?**
- Create service files in `/etc/systemd/system/` and use `systemctl` to manage them.
50. **How do you troubleshoot boot issues in Linux?**
- Check boot logs using `journalctl -xb`, review bootloader configuration, and ensure the kernel and
initramfs are correctly configured.
These questions cover fundamental and advanced Linux topics, providing a broad overview of
essential concepts and practical skills for interviews.