Linux Q&A
Notes: CompTIA+ Linux training
A compilation of notes that I've taken while studying for the Linux+ Certificate. The notes have been divided into Subjects to make it easier to follow, feel free to copy, use, modify and do whatever you want with this. Please do let me know if you find any mistakes or if there is anything that you would like me to change to make this more readable. Click HERE to get in touch with me.
GENERAL LINUX KNOWLEDGE
-
What are package managers? What package managers are available in Ubuntu and CentOS respectively?
Package managers are tools that automate the process of installing, updating, configuring, and removing software packages. In Ubuntu, the primary package manager is `apt`, which uses `.deb` packages. In CentOS, the primary package manager is `yum`, which uses `.rpm` packages.
-
What phases does the Linux booting process have? Explain each one of them.
The Linux booting process has several phases:
1. BIOS/UEFI: Initializes hardware and loads the bootloader.
2. Bootloader: Loads the kernel into memory (GRUB).
3. Kernel: Initializes system and mounts the root filesystem.
4. initramfs/initrd: Temporary filesystem used to bootstrap the actual root filesystem.
5. Init/Systemd: Manages system initialization and services. -
What is BIOS/UEFI/PXE and what do they do?
BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces that initialize hardware during the boot process and load the operating system. PXE (Preboot Execution Environment) allows a computer to boot from a network interface.
-
What is GRUB? Where is it located?
GRUB (GRand Unified Bootloader) is a bootloader used to load and transfer control to the operating system kernel. It is usually located in the Master Boot Record (MBR) or the EFI partition on UEFI systems.
-
What are pseudo/virtual file systems? Where are they located in Linux?
Pseudo or virtual file systems are special filesystems that do not correspond to actual files on disk but provide an interface to kernel data structures. Examples include `/proc` and `/sys`, which are located in the root directory.
-
What is GRUB2?
GRUB2 is the second version of the GRUB bootloader. It provides more advanced features and improved configuration over the original GRUB. It supports more operating systems and filesystems.
-
What does the “ls -al” command do?
The `ls -al` command lists all files and directories in the current directory, including hidden files, and displays detailed information such as permissions, number of links, owner, group, size, and modification date.
-
What are “initrd” and “initramfs” and what do they do?
`initrd` (initial ramdisk) and `initramfs` (initial RAM filesystem) are temporary root filesystems loaded into memory during the boot process to assist the kernel in mounting the real root filesystem. They contain necessary drivers and scripts.
-
What is kernel panic? And why does it happen?
A kernel panic is a safety measure taken by the operating system's kernel when it encounters a fatal error from which it cannot safely recover. It typically occurs due to hardware failures, corrupted filesystems, or buggy drivers.
-
What is the kernel?
The kernel is the core component of an operating system. It manages system resources, hardware communication, and provides essential services for all other parts of the operating system.
-
What does the “modprobe” command do?
The `modprobe` command is used to add or remove modules from the Linux kernel. It intelligently handles module dependencies and loads them as needed.
-
Where can you find the modules?
Kernel modules are typically located in the `/lib/modules/$(uname -r)/kernel/` directory. You can view the currently loaded modules using the `lsmod` command.
-
What does the
uname -r
command show you?The `uname -r` command displays the current running kernel version.
-
How can you view system logs in Linux?
System logs in Linux can be viewed using the `journalctl` command for systems with `systemd`, or by viewing log files in the `/var/log/` directory using commands like `cat`, `less`, or `tail`.
-
What are the differences between a hard link and a soft link in Linux?
A hard link is an additional directory entry for a file, pointing directly to the inode. A soft link (or symbolic link) is a pointer to another file's pathname. Hard links share the same inode and file content, while soft links are independent and can point to directories or files on different filesystems.
NETWORK CONFIGURATION
-
Where is the hostname configuration?
The hostname configuration can be found in the `/etc/hostname` file. Additionally, the `/etc/hosts` file may also contain hostname information.
-
What is the hostname for? How do you change it temporarily and permanently?
The hostname identifies a device on a network. To change it temporarily, use the `hostname` command. To change it permanently, edit the `/etc/hostname` file and update the `/etc/hosts` file as necessary.
-
Where can you find network connection files in CentOS and Ubuntu?
In CentOS, network connection files are located in `/etc/sysconfig/network-scripts/`. In Ubuntu, they are found in `/etc/network/interfaces` or managed by NetworkManager, with configurations in `/etc/NetworkManager/`.
-
What is DHCP?
DHCP (Dynamic Host Configuration Protocol) is a network management protocol used to automate the process of configuring devices on IP networks. It assigns IP addresses, subnet masks, gateways, and other network parameters.
-
What are the “ip”, “ping”, “ethtool” and “iwconfig” commands for?
The `ip` command is used for network interface configuration. The `ping` command tests connectivity between hosts. The `ethtool` command displays and modifies Ethernet device settings. The `iwconfig` command is used for configuring wireless network interfaces.
-
What is name resolution?
Name resolution is the process of converting human-readable domain names (like example.com) into IP addresses that computers use to identify each other on the network. This is typically done using DNS (Domain Name System).
-
What does the command “netstat -tuna” do?
The `netstat -tuna` command displays a list of active network connections (TCP and UDP), including their states, along with listening ports and addresses.
-
How do you change your hostname on Linux?
To change the hostname temporarily, use the `hostname` command followed by the new hostname. To change it permanently, edit the `/etc/hostname` file and update the `/etc/hosts` file accordingly. Reboot the system for the changes to take effect.
-
What are network bridges and what are they used for?
Network bridges connect two or more network segments, making them act as a single network. They are used in virtual networking to connect virtual machines to the physical network.
-
How can you create and take down bridges with Linux?
Use the `brctl` command to create a bridge (e.g., `brctl addbr br0`) and to add interfaces to it (e.g., `brctl addif br0 eth0`). To take down a bridge, use `brctl delbr br0`.
-
What command can you use to display routing tables on Linux?
The `route` command or `ip route show` can be used to display the routing table on Linux.
-
How do you make changes in the routing tables persistent?
To make routing table changes persistent, add the necessary routing commands to the network configuration files or use scripts that are executed at startup (e.g., adding routes to `/etc/network/interfaces` in Debian-based systems or using NetworkManager dispatcher scripts).
-
What is network bonding?
Network bonding combines multiple network interfaces into a single logical interface to increase bandwidth and provide redundancy. This is achieved using bonding drivers and configuration in `/etc/network/interfaces` or `/etc/sysconfig/network-scripts/` depending on the distribution.
-
What is network tuning?
Network tuning involves optimizing network settings for performance and efficiency. This can include adjusting kernel parameters, configuring network interfaces, optimizing TCP settings, and ensuring that the network hardware is functioning correctly.
STORAGE MANAGEMENT
-
What is the limit for primary partitions on MBR and what is the size limit?
The MBR (Master Boot Record) allows for a maximum of four primary partitions on a single disk. The size limit for each partition is 2 TB.
-
What is a primary partition?
A primary partition is a partition on a hard drive that can host an operating system. Up to four primary partitions can exist on a single MBR disk.
-
How do you add partitions on Linux?
Use tools like `fdisk`, `parted`, or `gparted` to add partitions. For example, `fdisk /dev/sda` allows you to create, delete, and manage partitions on the `/dev/sda` disk.
-
What are the /dev /sys /proc filesystems responsible for?
The `/dev` directory contains device files that represent hardware devices. The `/sys` directory provides information about the kernel and devices. The `/proc` directory contains virtual files that represent system and process information.
-
How can you check the disk space available on your partitions on Linux?
Use the `df` command to check disk space usage. For example, `df -h` displays the available disk space in a human-readable format.
-
Where is the first disk mounted on Linux?
The first disk is typically mounted as the root filesystem (`/`), but it can be mounted at any directory based on the system's configuration.
-
How can you create filesystems in Linux? Specifically ext4 or xfs files.
Use the `mkfs` command to create filesystems. For ext4, use `mkfs.ext4 /dev/sdXn`, and for xfs, use `mkfs.xfs /dev/sdXn`.
-
How can you mount and unmount partitions on Linux?
Use the `mount` command to mount partitions (e.g., `mount /dev/sdXn /mnt`). To unmount, use the `umount` command (e.g., `umount /mnt`).
-
How can you make the mounts persistent? What if the drive is encrypted?
To make mounts persistent, add entries to the `/etc/fstab` file. For encrypted drives, configure the encryption settings and add the appropriate entries in `/etc/crypttab` and `/etc/fstab`.
-
How can you mount external file systems?
Use the `mount` command with the appropriate filesystem type and device path. For example, `mount -t nfs server:/path /mnt` for NFS or `mount -t cifs //server/share /mnt` for CIFS/SMB.
-
What command do you use to view and detect multipath devices?
Use the `multipath` command to view and manage multipath devices. The `multipath -ll` command lists the detected multipath devices.
-
What commands can you use to troubleshoot filesystems?
Commands such as `fsck` (filesystem check), `blkid` (block device ID), `df` (disk free), and `du` (disk usage) are commonly used for troubleshooting filesystems.
CLOUD AND VIRTUALIZATION ON LINUX
-
What is a markup language?
A markup language is a system for annotating a document in a way that is syntactically distinguishable from the text. Examples include HTML and XML, which define the structure and presentation of content.
-
Why should containers and container images be used?
Containers and container images provide a lightweight, portable, and consistent environment for applications. They enable easier deployment, scalability, and management of applications across different environments.
-
How can you automate an installation on Linux (Anaconda Installer)?
Automate installation using the Anaconda Installer by creating a kickstart file, which contains configuration and installation instructions. Use the kickstart file during the installation process to automate the setup.
-
What’s the difference between thin and thick provisioned VM storage?
Thin provisioning allocates storage on demand, as data is written, saving space. Thick provisioning allocates the entire storage space upfront, ensuring the full capacity is reserved.
-
What are blob and block storage?
Blob storage is an object storage solution for unstructured data like images, videos, and documents. Block storage divides data into fixed-size blocks, ideal for databases and VMs.
-
What sorts of virtual networks can be used in virtualization? Why?
Virtual networks include NAT (Network Address Translation), bridged, and host-only networks. They enable connectivity, isolation, and efficient resource usage among virtual machines and between VMs and the host.
-
What is a hypervisor?
A hypervisor, or virtual machine monitor (VMM), is software that creates and manages virtual machines. Type 1 hypervisors run directly on hardware (bare-metal), while Type 2 run on a host operating system.
-
What commands can you use for virtualization on Linux?
Common virtualization commands include `virsh` for managing KVM virtual machines, `docker` for container management, and `VBoxManage` for VirtualBox VMs.
LOCALIZATION
-
What command can you use to check the localization?
Use the `locale` command to check the current localization settings, including language, character encoding, and time format.
-
Where can you find the timezone (file) in Ubuntu and CentOS? And where do they get the information from?
In Ubuntu and CentOS, the timezone is configured in the `/etc/timezone` file. The actual timezone data is sourced from the `/usr/share/zoneinfo` directory.
-
How can you modify the locale settings on Linux?
Modify locale settings by editing the `/etc/default/locale` file and using the `update-locale` command. You can also use `locale-gen` to generate new locale settings.
-
How can you set up the time and timezone through the command line?
Use the `timedatectl` command to set the time and timezone. For example, `timedatectl set-timezone America/New_York` sets the timezone to New York.
-
What command can you use to check the date?
Use the `date` command to display the current date and time. The command can also be used to set the date and time.
-
How can you manage the hardware clock on the system?
Manage the hardware clock using the `hwclock` command. For example, `hwclock --systohc` sets the hardware clock to the current system time, and `hwclock --hctosys` sets the system time to the hardware clock.
SOFTWARE MANAGEMENT
-
What types of packages are there? And for what distros?
There are binary packages (e.g., `.deb` for Debian-based systems, `.rpm` for Red Hat-based systems) and source packages. Binary packages contain precompiled software, while source packages contain source code that must be compiled.
-
How can you manage packages with ‘rpm’?
Use the `rpm` command to install, update, query, and remove RPM packages. For example, `rpm -ivh package.rpm` installs a package, and `rpm -qa` lists all installed packages.
-
What about ‘dpkg’?
Use the `dpkg` command to manage Debian packages. For example, `dpkg -i package.deb` installs a package, and `dpkg -l` lists all installed packages.
-
What commands can you use to manage packages in CentOS, Fedora, RHEL and SUSE?
Use `yum` or `dnf` for CentOS, Fedora, and RHEL to install, update, and remove packages. For SUSE, use `zypper`. Example: `yum install package` or `zypper install package`.
-
What’s the difference between ‘apt’ and ‘apt-get’?
`apt` is a more user-friendly command-line interface for managing packages on Debian-based systems, combining functionalities of `apt-get` and `apt-cache` with improved output formatting. `apt-get` is a lower-level tool with more granular options.
-
How can you extract files in Linux?
Use commands like `tar`, `unzip`, and `gunzip` to extract files. For example, `tar -xvf archive.tar` extracts a tar archive, and `unzip archive.zip` extracts a zip archive.
-
What is a compiler?
A compiler is a program that translates source code written in a high-level programming language into machine code that can be executed by a computer's CPU. Examples include `gcc` for C/C++ and `javac` for Java.
-
What is the ‘make’ command for?
The `make` command is used to build and manage projects based on a Makefile, which defines how to compile and link the program. It automates the compilation process by running the necessary commands specified in the Makefile.
-
How can you track down your libraries?
Use the `ldd` command to list the shared libraries required by a program. The `ldconfig` command updates the shared library cache. The `locate` and `find` commands can also be used to search for libraries.
-
How to fix Linux when you can’t find a library?
If a library is missing, you can install it using the package manager (`apt`, `yum`, etc.). If the library is installed but not found, update the library cache with `ldconfig`. Ensure the library path is included in `/etc/ld.so.conf` or specified in the `LD_LIBRARY_PATH` environment variable.
-
Where can you find repository files in CentOS and Ubuntu respectively?
In CentOS, repository files are located in `/etc/yum.repos.d/`. In Ubuntu, they are found in `/etc/apt/sources.list` and `/etc/apt/sources.list.d/`.
-
What are acquisition commands? Quote 2.
Acquisition commands are used to download and install packages. Examples include `apt-get install package` and `yum install package`.
FILE AND DIRECTORY MANAGEMENT
-
What command can you use to create a file or modify timestamps?
Use the `touch` command to create an empty file or update the access and modification times of an existing file. Example: `touch filename`.
-
What command can you use to view files in detail? And to check all timestamps?
Use the `ls -l` command to view files in detail. Use the `stat` command to check all timestamps (access, modification, and change times) of a file.
-
How can you change file permissions?
Use the `chmod` command to change file permissions. You can use symbolic (e.g., `chmod u+rwx filename`) or numeric (e.g., `chmod 755 filename`) modes to set permissions.
-
How can you change file ownership?
Use the `chown` command to change file ownership. Example: `chown user:group filename` changes the owner and group of the file.
-
How do you create and manage directories in Linux?
Use the `mkdir` command to create directories (e.g., `mkdir newdir`). Use the `rmdir` command to remove empty directories (e.g., `rmdir newdir`). Use `rm -r` to remove non-empty directories (e.g., `rm -r newdir`).
-
What is the difference between a hard link and a soft link? How do you create them?
A hard link is an additional directory entry for a file, pointing directly to the inode, sharing the same content. A soft link (or symbolic link) is a pointer to another file's pathname. Use `ln filename hardlink` for hard links and `ln -s filename symlink` for soft links.
-
How can you move or rename files and directories?
Use the `mv` command to move or rename files and directories. Example: `mv oldname newname` renames a file, and `mv filename /newpath/` moves a file to a new directory.
-
How can you delete files and directories?
Use the `rm` command to delete files (e.g., `rm filename`). Use `rm -r` to delete directories and their contents recursively (e.g., `rm -r dirname`).
-
What command can you use to search for files in Linux?
Use the `find` command to search for files based on criteria such as name, size, or modification date. Example: `find /path -name filename` searches for a file by name.
-
How can you display the contents of a file?
Use commands like `cat`, `less`, `more`, `head`, and `tail` to display the contents of a file. Example: `cat filename` displays the entire file, while `less filename` allows for paginated viewing.
-
How can you find out the size of a directory?
Use the `du` command to check the size of a directory and its contents. Example: `du -sh dirname` provides a summary of the directory size in human-readable format.
-
What command can you use to copy files and directories?
Use the `cp` command to copy files and directories. Example: `cp sourcefile destfile` copies a file, and `cp -r sourcedir destdir` copies a directory recursively.
-
How do you create and extract archives in Linux?
Use the `tar` command to create and extract archives. Example: `tar -cvf archive.tar dirname` creates an archive, and `tar -xvf archive.tar` extracts it. Use `gzip` or `bzip2` for compression (e.g., `tar -czvf archive.tar.gz dirname`).
-
How can you set default permissions for newly created files and directories?
Use the `umask` command to set default permissions for newly created files and directories. Example: `umask 022` sets the default permissions to `755` for directories and `644` for files.
-
What is the purpose of the `/etc/fstab` file?
The `/etc/fstab` file defines how disk partitions, devices, and remote filesystems should be mounted at boot time. It contains information about the filesystems and their mount points.
-
How can you find and remove empty directories?
Use the `find` command to locate empty directories and remove them. Example: `find /path -type d -empty -delete` finds and deletes all empty directories in the specified path.
-
How can you display the first few lines or the last few lines of a file?
Use the `head` command to display the first few lines (e.g., `head -n 10 filename`) and the `tail` command to display the last few lines (e.g., `tail -n 10 filename`) of a file.
-
What command can you use to count the number of lines, words, and characters in a file?
Use the `wc` (word count) command to count the number of lines, words, and characters in a file. Example: `wc filename` displays all counts, while `wc -l filename` shows only the number of lines.
-
How do you create symbolic links for directories?
Use the `ln -s` command to create symbolic links for directories. Example: `ln -s /path/to/original /path/to/link` creates a symbolic link to a directory.
-
How can you monitor changes to a file in real-time?
Use the `tail -f` command to monitor changes to a file in real-time. Example: `tail -f logfile` displays new lines added to the file as they appear.
SECURITY MANAGEMENT
-
How can you manage user and group permissions?
Manage user and group permissions using the `chmod`, `chown`, and `chgrp` commands. `chmod` changes file permissions, `chown` changes file owner, and `chgrp` changes group ownership. Use access control lists (ACLs) for finer-grained permissions.
-
What are SELinux and AppArmor?
SELinux (Security-Enhanced Linux) and AppArmor are Linux security modules that provide mandatory access control (MAC). SELinux uses security policies to enforce access rules, while AppArmor uses profile-based access control.
-
How can you configure a firewall using iptables?
Configure a firewall using `iptables` by defining rules to allow or block traffic. Example: `iptables -A INPUT -p tcp --dport 22 -j ACCEPT` allows SSH traffic. Save rules with `iptables-save` and restore with `iptables-restore`.
-
What are the steps to encrypt data on a Linux system?
Encrypt data using tools like `gpg` for files and `cryptsetup` with LUKS for disk encryption. Steps include creating a key, encrypting the data, and securely storing the key. Example: `gpg -c filename` encrypts a file with a passphrase.
-
How do you manage SSH configuration and security?
Manage SSH configuration in the `/etc/ssh/sshd_config` file. Enhance security by disabling root login (`PermitRootLogin no`), using key-based authentication, changing the default port, and configuring firewall rules. Restart SSH service after changes.
-
What tools can you use for auditing and logging in Linux?
Use tools like `auditd` for auditing system calls, `rsyslog` for logging system events, and `logrotate` for managing log file rotation. Example: `auditctl` to configure audit rules and `ausearch` to search audit logs.
-
How do you apply security updates and patches?
Apply security updates using package managers. Example: `apt-get update && apt-get upgrade` on Debian-based systems, `yum update` on Red Hat-based systems. Configure automatic updates using tools like `unattended-upgrades` or `yum-cron`.
-
What is an Intrusion Detection System (IDS)?
An Intrusion Detection System (IDS) monitors network traffic or system activities for malicious actions or policy violations. Examples include Snort (network-based IDS) and OSSEC (host-based IDS).
-
How do you configure and manage SELinux policies?
Configure SELinux policies using tools like `semanage` and `setsebool`. Manage policies by setting SELinux modes (`enforcing`, `permissive`, `disabled`) in `/etc/selinux/config`. Use `audit2allow` to create custom policies based on audit logs.
-
How can you implement password policies and account lockout?
Implement password policies using PAM (Pluggable Authentication Modules). Edit `/etc/pam.d/common-password` to enforce complexity and expiration rules. Use `faillock` to configure account lockout policies after failed login attempts.
SYSTEM MAINTENANCE
-
How do you update and upgrade a Linux system?
Use package managers to update and upgrade a Linux system. Example: `apt-get update` to refresh package lists and `apt-get upgrade` to upgrade installed packages on Debian-based systems. Use `yum update` on Red Hat-based systems.
-
What commands can you use to manage services on Linux?
Manage services using `systemctl` on systemd-based systems. Example: `systemctl start servicename`, `systemctl stop servicename`, `systemctl enable servicename`, and `systemctl status servicename`. Use `service` and `chkconfig` on older systems.
-
How can you schedule jobs using cron and at?
Schedule recurring jobs using `cron` by editing the crontab file (`crontab -e`). Schedule one-time jobs using `at` (e.g., `echo "command" | at 10:00 AM`). View scheduled `at` jobs with `atq` and remove them with `atrm`.
-
What are the best practices for backing up and restoring data?
Best practices include regular backups, using tools like `rsync`, `tar`, and `dd`. Store backups in multiple locations (local, remote, cloud). Test backups regularly. Use versioning and encryption for added security.
-
How do you document system configurations and changes?
Document system configurations and changes using tools like `etckeeper` to track changes in `/etc`. Maintain change logs and configuration files in a version control system like Git. Keep detailed records of system settings and updates.
-
What techniques can you use for troubleshooting common issues?
Techniques include checking log files (`journalctl`, `/var/log/`), using diagnostic commands (`dmesg`, `top`, `free`), verifying configurations, testing network connectivity (`ping`, `traceroute`), and isolating issues through process of elimination.
-
How can you automate system maintenance tasks?
Automate system maintenance tasks using scripts and scheduling tools like `cron` and `systemd` timers. Example: Schedule regular updates (`apt-get update && apt-get upgrade`) and cleanup tasks (`tmpwatch`, `logrotate`).
-
What tools are available for system performance monitoring?
Tools for performance monitoring include `top`, `htop`, `iotop`, `vmstat`, `sar`, `dstat`, `nmon`, and `glances`. Use these tools to monitor CPU, memory, disk I/O, and network usage.
-
How do you manage disk space and inodes?
Manage disk space using `df` to check free space and `du` to analyze directory sizes. Use `tune2fs` to adjust inode settings. Clean up unnecessary files (`rm`, `tmpwatch`) and use filesystem quotas to limit usage (`quota`).
-
What are the steps to safely shut down or reboot a Linux system?
Safely shut down or reboot using `shutdown` (`shutdown -h now` for halt, `shutdown -r now` for reboot). Use `reboot` or `halt` commands. Notify users with `wall` or `shutdown` messages. Ensure all processes are terminated cleanly.
TROUBLESHOOTING
-
How do you troubleshoot boot issues in Linux?
Troubleshoot boot issues by checking bootloader configuration (`/boot/grub/grub.cfg`), examining boot logs (`journalctl -b`), and using recovery mode or live CD to repair the bootloader or filesystem. Verify kernel parameters and initramfs.
-
What steps do you take to resolve network connectivity problems?
Resolve network connectivity problems by checking physical connections, verifying IP configuration (`ip addr`), testing connectivity (`ping`, `traceroute`), examining routing tables (`ip route`), and reviewing firewall rules. Restart network services if needed.
-
How can you diagnose and fix filesystem errors?
Diagnose and fix filesystem errors using `fsck` (filesystem check). Unmount the filesystem (`umount /dev/sdXn`) and run `fsck /dev/sdXn` to check and repair. Examine logs for errors (`dmesg`, `/var/log/messages`) and ensure sufficient free space.
-
What tools can you use to troubleshoot software and package issues?
Use tools like `strace` to trace system calls, `lsof` to list open files, and package managers (`apt`, `yum`, `dpkg`, `rpm`) to verify and repair software installations. Check logs for errors and conflicts.
-
How do you identify and resolve hardware problems on Linux?
Identify and resolve hardware problems using `dmesg` to check for hardware-related messages, `lspci` and `lsusb` to list hardware devices, and `smartctl` to check disk health. Replace or reconfigure faulty hardware as needed.
-
What are the common performance issues and how do you address them?
Common performance issues include high CPU or memory usage, disk I/O bottlenecks, and network latency. Address them using tools like `top`, `htop`, `iotop`, and `nmon` to identify resource hogs, optimize configurations, and upgrade hardware if necessary.
-
How can you use log files to diagnose problems?
Diagnose problems using log files located in `/var/log/`. Use `journalctl` for systemd logs, `tail -f` to monitor logs in real-time, and `grep` to search for specific errors or events. Regularly review and analyze logs for issues.
-
What is the process for troubleshooting user permission issues?
Troubleshoot user permission issues by checking file and directory permissions (`ls -l`), verifying group membership (`id`), and using `chmod`, `chown`, and `chgrp` to adjust permissions. Check SELinux/AppArmor policies if applicable.
-
How do you recover from a system crash or kernel panic?
Recover from a system crash or kernel panic by rebooting into a rescue mode or live CD, examining logs (`journalctl`, `/var/log/messages`), and checking for hardware issues. Update or reinstall the kernel if needed. Backup data regularly to prevent loss.
-
What techniques can you use to troubleshoot application crashes?
Troubleshoot application crashes by checking logs, running the application in debug mode, using tools like `strace` to trace system calls, and verifying dependencies. Update or reinstall the application if necessary.
AUTOMATION AND SCRIPTING
-
What are the basics of shell scripting in Linux?
Shell scripting involves writing scripts using a shell like Bash to automate tasks. Basics include defining variables, using control structures (if, for, while), and executing commands. Scripts start with a shebang (`#!/bin/bash`) to specify the interpreter.
-
How can you automate tasks using shell scripts?
Automate tasks by writing shell scripts to execute a series of commands. Schedule scripts with `cron` for recurring tasks or `at` for one-time tasks. Example: a backup script that runs daily via a cron job.
-
What are the common shell scripting constructs and their uses?
Common constructs include variables (`var=value`), conditionals (`if [ condition ]; then`), loops (`for var in list; do`), and functions (`function_name() {}`). They allow for dynamic and flexible script execution.
-
How do you manage system configurations using scripts?
Manage system configurations by scripting the modification of configuration files, applying system settings, and automating repetitive admin tasks. Use tools like `sed`, `awk`, and `ansible` for efficient configuration management.
-
What tools can you use for configuration management (e.g., Ansible, Puppet, Chef)?
Tools like Ansible, Puppet, and Chef automate configuration management and deployment. Ansible uses YAML playbooks, Puppet uses declarative manifests, and Chef uses Ruby-based cookbooks to define system states and automate configurations.
-
How do you automate system monitoring with scripts?
Automate system monitoring by scripting the collection of performance metrics (`vmstat`, `iostat`), logging system status (`uptime`), and sending alerts (`mail`, `notify-send`). Schedule these scripts with `cron` for regular monitoring.
-
What is the role of environment variables in scripting?
Environment variables store values that affect the behavior of processes and scripts. They are used to pass configuration settings and user preferences. Example: `PATH` defines directories to search for executables.
-
How can you handle errors and debugging in shell scripts?
Handle errors using exit statuses (`exit 1`), error messages (`echo "Error message"`), and conditional checks. Debug scripts with `set -x` for command tracing and `set -e` to exit on errors. Use `trap` to handle signals and cleanup.
-
What are the best practices for writing maintainable scripts?
Best practices include using clear and consistent naming conventions, adding comments for documentation, modularizing code into functions, handling errors gracefully, and using version control (e.g., Git) for script management.
-
How do you schedule automated scripts using cron and at?
Schedule automated scripts with `cron` for recurring tasks by editing the crontab file (`crontab -e`). Use `at` for one-time tasks (e.g., `echo "script.sh" | at 10:00`). Verify scheduled jobs with `crontab -l` and `atq`.