Q 1. What is Linux?
Ans. Linux is an open-source, Unix-like operating system kernel that is widely used in servers, desktops, and embedded systems. It is known for its stability, security, and flexibility.
Q 2. What are the basic components of Linux?
Ans. The basic components include the kernel, system libraries, system utilities, and application programs.
Q 3. How do you check the current kernel version?
Ans. Use the command uname -r.
Q 4. How do you list all files in a directory?
Ans. Use the command ls. To list all files including hidden ones, use ls -a.
Q 5. What command is used to change file permissions?
Ans. The chmod command is used to change file permissions.
Q 6. How do you view the contents of a file?
Ans. Use commands like cat, more, less, head, or tail.
Q 7. What is a shell in Linux?
Ans. A shell is a command-line interpreter that provides a user interface for the Linux operating system.
Q 8. How do you create a new directory in Linux?
Ans. Use the mkdir command followed by the directory name.
Q 9. What is the purpose of the grep command?
Ans. The grep command is used to search for specific patterns within files.
Q 10. How do you check disk usage in Linux?
Ans. Use the df command for file system disk space usage and du for directory space usage.
Q 11. What is the difference between sudo and su?
Ans. sudo allows a permitted user to execute a command as the superuser or another user, while su switches the current user to another user.
Q 12. How do you view running processes in Linux?
Ans. Use the ps, top, or htop commands.
Q 13. What is a symbolic link?
Ans. A symbolic link is a type of file that points to another file or directory.
Q 14. How do you compress files in Linux?
Ans. Use commands like gzip, bzip2, tar, or zip.
Q 15. What is the cron command used for?
Ans. The cron command is used to schedule tasks to run at specified intervals.
Q 16. How do you find the IP address of your Linux system?
Ans. Use commands like ifconfig, ip addr, or hostname -I.
Q 17. What is the /etc/passwd file?
Ans. It is a file that contains user account information.
Q 18. How do you display the first 10 lines of a file?
Ans. Use the head command.
Q 19. How do you check the memory usage in Linux?
Ans. Use the free command or check /proc/meminfo.
Q 20. What is a runlevel in Linux?
Ans. A runlevel is a mode of operation in the Unix-based operating systems that defines what system services are operating.
Q 21. How do you change the default runlevel?
Ans. Edit the /etc/inittab file (on older systems) or use systemctl set-default on systems with systemd.
Q 22. What is SELinux?
Ans. SELinux (Security-Enhanced Linux) is a security architecture integrated into the kernel that provides mandatory access control.
Q 23. How do you view system logs in Linux?
Ans. Use the journalctl command on systems with systemd or view files in /var/log.
Q 24. What is a Linux kernel module?
Ans. A kernel module is a piece of code that can be loaded into the kernel to extend its functionality without rebooting the system.
Q 25. How do you load a kernel module?
Ans. Use the modprobe or insmod command.
Q 26. What is a swap space?
Ans. Swap space is a portion of the hard disk used as virtual memory when the RAM is fully utilized.
Q 27. How do you check which services are running on a Linux system?
Ans. Use the systemctl command on systems with systemd or service --status-all on older systems.
Q 28. What is the fstab file?
Ans. It is a configuration file that contains information about disk partitions and their mount points.
Q 29. How do you mount a filesystem?
Ans. Use the mount command followed by the device name and the mount point.
Q 30. How do you unmount a filesystem?
Ans. Use the umount command followed by the mount point or device name.
Q 31. What is the iptables command used for?
Ans. iptables is used to configure the Linux kernel firewall.
Q 32. What is a daemon in Linux?
Ans. A daemon is a background process that runs continuously to handle requests for services such as web servers, database servers, etc.
Q 33. How do you set environment variables in Linux?
Ans. Use the export command in the shell or edit the appropriate profile files like ~/.bashrc or /etc/profile.
Q 34. What is the difference between hard links and soft links?
Ans. A hard link is a direct pointer to the data on the disk, whereas a soft link (or symbolic link) is a pointer to another file name.
Q 35. How do you update a package in Linux?
Ans. Use the package manager specific to the distribution, such as apt-get upgrade for Debian-based systems or yum update for Red Hat-based systems.
Q 36. What is the nohup command used for?
Ans. The nohup command is used to run a command immune to hangups, allowing the command to continue running in the background after the user has logged out.
Q 37. How do you secure a Linux server?
Ans. Implement strong passwords, disable root login, use SSH keys, keep the system updated, configure a firewall, and use security tools like SELinux or AppArmor.
Q 38. What is the lsof command?
Ans. lsof stands for List Open Files, and it is used to display all open files and the processes that opened them.
Q 39. How do you troubleshoot a network issue in Linux?
Ans. Use tools like ping, traceroute, ifconfig, netstat, tcpdump, and nslookup to diagnose network problems.
Q 40. Explain how you would troubleshoot a system that is running very slow?
Ans. To troubleshoot a slow system, I would,
- Check CPU usage using top or htop to identify processes consuming high CPU.
- Check memory usage with free -m and identify memory hogs using ps aux --sort=-%mem.
- Look at disk I/O performance using iotop or iostat.
- Ensure there is no disk space issue by running df -h.
- Check for excessive swapping with vmstat 1 5.
- Inspect system logs in /var/log and use journalctl for any unusual activities.
- Verify network performance using netstat, ss, and iftop.
Q 41. How do you handle kernel panic issues in Linux?
Ans. To handle kernel panic issues.
- Check logs: Review /var/log/messages, /var/log/syslog, and dmesg for any relevant messages.
- Examine hardware: Ensure there are no hardware failures, like faulty RAM or overheating.
- Check kernel updates: Ensure the kernel is up to date and consider rolling back recent updates if they are causing issues.
- Verify system configuration: Check for incorrect configurations in system files and boot parameters.
- Test kernel modules: Remove or update any problematic kernel modules.
- Use kdump: Configure kdump to capture core dumps for further analysis.
Q 42. Describe the process of setting up and using LVM (Logical Volume Manager) in Linux.
Ans. To set up and use LVM.
- Install LVM tools: Ensure lvm2 package is installed.
- Create physical volumes (PVs): pvcreate /dev/sdX.
- Create a volume group (VG): vgcreate my_vg /dev/sdX.
- Create logical volumes (LVs): lvcreate -L 10G -n my_lv my_vg.
- Format the LV: mkfs.ext4 /dev/my_vg/my_lv.
- Mount the LV: mount /dev/my_vg/my_lv /mnt.
- Extend an LV: lvextend -L +5G /dev/my_vg/my_lv followed by resize2fs /dev/my_vg/my_lv.
Q 43. How would you set up and manage SELinux on a Linux system?
Ans. To set up and manage SELinux.
- Install SELinux tools: Ensure policycoreutils, selinux-policy, and setroubleshoot packages are installed.
- Check SELinux status: Use sestatus.
- Enable/disable SELinux: Edit /etc/selinux/config and set SELINUX=enforcing (or permissive/disabled).
- Set SELinux contexts: Use chcon for temporary changes or semanage fcontext and restorecon for persistent changes.
- Manage booleans: Use getsebool and setsebool to manage SELinux booleans.
- Troubleshoot: Use audit2allow to create custom policies from audit logs.
Q 44. Explain the Linux boot process in detail.
Ans. The Linux boot process consists of several stages.
- BIOS/UEFI Initialization: The system firmware initializes hardware and runs a Power-On Self Test (POST).
- Bootloader Stage: The bootloader (GRUB, LILO) is loaded from the MBR/GPT. It presents a menu to choose the OS and loads the selected kernel into memory.
- Kernel Initialization: The kernel initializes the hardware, mounts the root filesystem, and starts the init system.
- Init/Systemd Stage: The init process (or systemd) takes over, executes startup scripts, and brings the system to the desired runlevel or target.
- Runlevel/Target Stage: Services and daemons are started according to the runlevel/target configuration.
Q 45. How do you secure a Linux server?
Ans.
- Update and Patch Regularly: Keep the system and applications up to date.
- Firewall Configuration: Use iptables or firewalld to configure firewall rules.
- SSH Security: Disable root login, use SSH keys instead of passwords, and change the default SSH port.
- Intrusion Detection Systems: Implement tools like Fail2Ban, AIDE, and SELinux/AppArmor.
- User and Group Management: Use least privilege principles, strong passwords, and sudo for administrative tasks.
- Disable Unnecessary Services: Turn off services that are not needed.
- Regular Audits: Perform security audits and use tools like Lynis and OpenVAS.
Q 46. Explain the role of Linux in cloud computing environments.
Ans.
- Linux is the dominant operating system in cloud computing environments, powering a significant portion of cloud infrastructure and services.
- It provides scalability, flexibility, and robustness, making it well-suited for building and managing cloud-based applications and services.
- Example: Using Linux distributions like Ubuntu, CentOS, or Amazon Linux as the base operating system for cloud instances on platforms like AWS, Azure, or Google Cloud Platform.
Q 47. Can you explain the concept of Linux namespaces and their significance in containerization?
Ans. Linux namespaces are a kernel feature that provides isolation mechanisms for various system resources, such as process IDs, network interfaces, mount points, and user IDs. They allow processes to have their own isolated view of the system, enabling containerization technologies like Docker and Kubernetes to create lightweight, portable, and isolated environments. Namespaces ensure that processes within a container are isolated from processes outside the container, improving security and resource utilization.
Q 48. What are cgroups in Linux? How are they used in resource management?
Ans.
- Control groups (cgroups) are a Linux kernel feature for resource management and allocation.
- They allow the allocation of system resources such as CPU, memory, disk I/O, and network bandwidth to processes or groups of processes.
- Cgroups provide mechanisms for limiting, prioritizing, and monitoring resource usage.
- They are used in containerization technologies to enforce resource constraints and isolation between containers.
- Cgroups can be managed using tools like systemd, Docker, or directly through the cgroup file system (/sys/fs/cgroup).
Q 49. Explain the difference between RAID 0, RAID 1, and RAID 5.
Ans.
- RAID 0 (striping) offers improved performance by spreading data across multiple disks, but it provides no redundancy or fault tolerance.
- RAID 1 (mirroring) duplicates data across multiple disks, providing fault tolerance but no performance improvement.
- RAID 5 (striping with distributed parity) combines striping with parity data distributed across all disks, providing both performance improvement and fault tolerance.
- RAID 5 requires a minimum of three disks and can tolerate the failure of one disk without data loss.
- RAID 0 and RAID 1 are simpler and have lower overhead compared to RAID 5.
Q 50. What are the differences between TCP and UDP? When would you use each one?
Ans.
- TCP (Transmission Control Protocol) provides reliable, connection-oriented communication with error detection and correction.
- UDP (User Datagram Protocol) is connectionless and provides unreliable, datagram-oriented communication without error checking.
- TCP guarantees the delivery of data packets in the correct order, while UDP does not guarantee delivery or order.
- TCP is suitable for applications requiring reliable data transmission, such as HTTP, FTP, and SSH.
- UDP is preferred for real-time applications like VoIP, streaming media, and online gaming, where low latency is more important than guaranteed delivery.