CompTIA Linux+ (XK0-006) practice questions
208 free questions with answers and explanations.
- 101.A developer needs to write a Python script that executes an external shell command and captures its standard output and standard error streams separately. The script must also check the exit code of the command. Which `subprocess` module function is best suited for this task?Automation, Orchestration and Scripting
- 102.A server administrator suspects a service failure occurred during the most recent boot and wants to view only journal entries with a priority of 'err' or higher from that boot. Which command should be used?System Management
- 103.A network engineer wants to extract all IP addresses (IPv4 format) from a log file named `access.log`. The IP addresses can appear anywhere on a line. Which of the following `grep` commands, using regular expressions, will correctly find and display all IPv4 addresses?Automation, Orchestration and Scripting
- 104.A web application listens on TCP port 8443 and `ss -tlnp` confirms it is in the LISTEN state on the server. However, external clients cannot connect and receive connection timeouts. Which command permanently allows inbound traffic on this port through firewalld?Troubleshooting
- 105.A security engineer configuring PAM on a Linux server needs to understand the order in which PAM management groups are typically processed for a login attempt. Which group is responsible for verifying the user's identity, such as checking a password against a stored hash?Security
- 106.A developer needs to clone a Git repository from a private server and then immediately switch to a specific branch named `feature/new-api`. Which sequence of Git commands will accomplish this efficiently?Automation, Orchestration and Scripting
- 107.A pilot deployment of a database server shows the following in `top`: load average: 8.50, 4.20, 2.10 The server has 4 CPU cores. What does this load average trend most likely indicate?Troubleshooting
- 108.A system administrator is troubleshooting a virtual machine that boots to a `(initramfs)` prompt. The server was recently migrated to a new hypervisor. The administrator suspects a missing driver for the new virtualized disk controller. Which command, run from the `initramfs` prompt, would be most effective in confirming this suspicion and potentially identifying the missing module?Troubleshooting
- 109.A network administrator is configuring a firewall rule to block inbound traffic on TCP port 8080 from an untrusted subnet. The administrator wants the remote client to receive immediate feedback (such as a TCP reset or ICMP unreachable message) that the connection was refused, rather than have the connection attempt silently time out. Which firewall action should be used?Security
- 110.According to the Filesystem Hierarchy Standard (FHS), a vendor is installing a self-contained third-party application suite that includes its own directory structure and should not be mixed with the distribution's package-managed files. Which directory is the standard location for this software?System Management
- 111.A server administrator wants a headless Linux server to always boot into a non-graphical, multi-user command-line environment by default. Which command accomplishes this?System Management
- 112.A system administrator notices that a newly deployed web server is unreachable from the internet, although it can ping other internal servers. The web server's firewall configuration was recently updated. Which command should the administrator use to verify if the web server is listening on the correct port and if the firewall is blocking incoming connections to that port?Troubleshooting
- 113.A client wants a junior administrator, jdoe, to be able to restart the httpd service using sudo without being prompted for a password, while all other sudo commands for jdoe still require password authentication. Which line, added via visudo, achieves this?Security
- 114.A user reports that they are unable to connect to a web application running on a Linux server via SSH, even though they can `ping` the server's IP address. The application is confirmed to be listening on TCP port 2222. The administrator discovers that the server's firewall (using `firewalld`) is currently configured to allow only SSH (port 22) and HTTP (port 80) services. Which `firewall-cmd` command would allow access to the web application without permanently opening port 2222 for all services?Troubleshooting
- 115.A technician needs to run `fsck` on the root filesystem (/) of a running server to check for errors. What is the safest way to accomplish this?Troubleshooting
- 116.A system administrator is writing an Ansible playbook to deploy a web application. The application requires a specific configuration file, `/etc/myapp/config.yaml`, to be present on all web servers. The content of this file varies slightly based on the environment (e.g., development, staging, production) but shares a common structure. Which Ansible module is best suited for deploying this configuration file with environment-specific variables?Automation, Orchestration and Scripting
- 117.A system administrator is writing a Bash script to automate the backup of critical configuration files. The script needs to ensure that it only proceeds if the backup directory exists and is writable. Which of the following conditional statements effectively checks if the directory `/var/backups/config` exists and is writable by the script's user?Automation, Orchestration and Scripting
- 118.A system administrator needs to create a new user account named `appuser` with a specific UID of `2000`, a primary GID of `2000`, a home directory at `/srv/appuser`, and a default shell of `/bin/bash`. Which command correctly accomplishes this?Services and User Management
- 119.A technician has attached a new 4TB disk, /dev/sdb, to a Linux server. Because MBR partition tables cannot support disks larger than 2TB, the technician needs to create a GPT partition table before adding partitions. Which command accomplishes this?System Management
- 120.A system administrator is auditing user accounts and needs to find out when the password for the user `jdoe` was last changed, and when it is set to expire. Which file contains this information?Services and User Management
- 121.A Python developer is writing a script that needs to create a directory if it doesn't already exist. Which of the following Python code snippets correctly achieves this, preventing an error if the directory already exists?Automation, Orchestration and Scripting
- 122.A virtual machine is migrated to a new hypervisor that uses a virtio disk controller instead of the original IDE controller. On boot, the system halts at a dracut emergency shell with the message "Gave up waiting for root device." After booting from rescue media and chrooting into the system, which command should the technician run to resolve this?Troubleshooting
- 123.An administrator runs 'sudo -l' as user jdoe and needs to interpret the output to determine what jdoe is authorized to do. What does this command display?Security
- 124.A technician needs to verify the exact installed version and release number of the 'httpd' package on a Fedora-based server without querying remote repositories. Which command should be used?System Management
- 125.A system administrator is using Ansible to manage server configurations. They need to create a new user account named `devuser` on a target server, ensure it belongs to the `developers` group, and set its primary shell to `/bin/bash`. If the user already exists, Ansible should ensure its properties match these specifications. Which Ansible module and parameters should be used?Automation, Orchestration and Scripting
- 126.A DevOps engineer is setting up a Git repository for a new project. They want to ensure that all developers use a consistent code style and that certain linting checks are performed automatically before any commit is finalized. Which Git feature should the engineer configure to enforce these checks?Automation, Orchestration and Scripting
- 127.A system administrator needs to configure a `systemd` service named `myservice.service` to automatically restart whenever its main process exits unexpectedly (e.g., due to a crash). Which directive should be added to the `[Service]` section of the unit file?Services and User Management
- 128.A system administrator is investigating why a `systemd` service named `mybackup.service` is not running as expected. The service is configured to run a script every day at 02:00. Upon checking `systemctl status mybackup.service`, it shows `inactive (dead)`. What is the most likely reason for this status given the description?Services and User Management
- 129.A junior administrator is troubleshooting a Linux server and needs to know where system-wide log files such as syslog and boot messages are stored according to the Filesystem Hierarchy Standard (FHS). Which directory should they check?System Management
- 130.A system administrator needs to restrict a user named `devuser` from accessing certain sensitive files in the `/var/log/secure` directory, even though the directory has global read permissions. The administrator wants to explicitly deny `devuser` read access to `/var/log/secure` without affecting other users or groups. Which command sequence using Access Control Lists (ACLs) would achieve this?Services and User Management
- 131.A technician manually configured a static IP address on eth0 using 'ip addr add 192.168.1.50/24 dev eth0'. The host can reach other devices on the local subnet but cannot reach any external networks. Which command is most likely needed to fix this issue?System Management
- 132.A technician boots a rescue environment to repair a broken system installed at /mnt/sysimage. Before running 'chroot /mnt/sysimage', the technician needs the rescue environment's /dev directory to be accessible inside the chroot at the same path. Which command accomplishes this?System Management
- 133.A system administrator is developing a Bash script to manage user accounts. The script needs to iterate through a list of usernames provided in a file, `users.txt`, and perform an action for each user. The `users.txt` file contains one username per line. Which Bash construct is the most robust way to read each line from `users.txt` and process it within a loop, correctly handling usernames that might contain spaces?Automation, Orchestration and Scripting
- 134.An administrator investigates a server with poor responsiveness and runs `top`, noticing several processes in state `Z` that persist over many refresh cycles. What is the correct explanation and remedy for these processes?Troubleshooting
- 135.A junior administrator needs to modify the default umask for all newly created users on a Linux server to `0027`. This change should be system-wide and persist across reboots. Which file should the administrator edit?Services and User Management
- 136.A server administrator needs to transfer a large file from a local workstation to a remote Linux server using a secure, efficient, and scriptable method. Which command is best suited for this task?System Management
- 137.A technician wants an entry in /etc/fstab for /dev/sdb1 mounted at /backup to NOT be mounted automatically during boot, but still allow an administrator to run 'mount /backup' manually later. Which mount option should be added to that fstab entry?System Management
- 138.A user reports that they can't access a critical application's data files located at `/opt/app/data`. The administrator checks the permissions with `ls -l /opt/app` and sees the following output: ``` drwx------ 2 root root 4096 Apr 20 10:00 data ``` The application runs as the user `appuser` and is a member of the `appgroup` group. What is the most likely cause of the access denied error and how should it be resolved?Troubleshooting
- 139.A newly installed database server is experiencing high CPU utilization, with `top` showing a significant percentage for `sy` (system CPU usage) and `si` (software interrupts). This occurs even when the database itself is not under heavy load. The server has multiple network interfaces, and the administrator suspects excessive network interrupt handling. Which command would help identify which specific network interface is generating the most software interrupts?Troubleshooting
- 140.A volume group 'vg_data' has run out of free space. A technician adds a new physical disk, partitions it as /dev/sdd1, and initializes it as a physical volume with 'pvcreate /dev/sdd1'. Which command should be run next to add this new physical volume's space into the existing volume group so it can be used to extend a logical volume?System Management
- 141.A system administrator is troubleshooting a server experiencing high CPU utilization. Upon checking `top`, they notice a significant percentage of CPU time being spent in the `si` (software interrupt) column, often associated with `ksoftirqd`. Which of the following is the most likely cause of high `si` CPU usage?Troubleshooting
- 142.An administrator adds a new physical volume to a volume group and extends the logical volume for /home with `lvextend -L +10G /dev/vgdata/lvhome`. The /home filesystem uses XFS. After running the command, `df -h` still shows the old, smaller size for /home. What step was missed?Troubleshooting
- 143.A technician runs `vmstat 2` on a sluggish application server and observes the following steady-state output: procs -----------memory---------- ---swap-- -----io---- ---system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 3 512000 20480 10240 102400 850 920 1200 1400 3000 4500 10 5 20 65 0 What does the si and so column data most strongly indicate?Troubleshooting
- 144.A pilot deployment adds a new external drive, /dev/sdc1, to a server. The technician wants the drive to always mount reliably at /data even if the device name changes after a reboot (e.g., becomes /dev/sdd1). What should the technician do first, and what should the /etc/fstab entry reference?System Management
- 145.A developer is writing a Python script that needs to convert a string representing a JSON object into a Python dictionary. The string is `json_string = '{"name": "Alice", "age": 30}'`. Which Python module and function should be used to perform this conversion?Automation, Orchestration and Scripting
- 146.A system administrator is investigating a Linux server that unexpectedly rebooted. The last messages in `/var/log/messages` (or `journalctl`) before the reboot indicate `kernel: Out of memory: Kill process 1234 (apache2) score 999 or sacrifice child`. Which type of system performance issue is primarily indicated by this log entry?Troubleshooting
- 147.A developer is writing a Python script to automate file processing. The script needs to iterate through a list of filenames, open each file, read its content, and then close it. Which Python construct is best suited for ensuring that a file is always properly closed, even if errors occur during content processing?Automation, Orchestration and Scripting
- 148.A web server's content directory was recently restored from an archive using `tar`. Users receive HTTP 403 Forbidden errors even though `ls -l /var/www/html` shows correct ownership (apache:apache) and permissions (644 for files, 755 for directories). SELinux is enabled and set to Enforcing. Which command most directly resolves this issue?Troubleshooting
- 149.A system administrator wants to limit the number of concurrent login sessions for a specific user, `devuser`, to a maximum of 3. Which configuration file should be modified to achieve this?Services and User Management
- 150.A technician has three new, unpartitioned disks: /dev/sdb, /dev/sdc, and /dev/sdd. Which sequence of commands correctly initializes them for LVM, groups them into a single volume group named vg_data, and then creates a 50GB logical volume named lv_app?System Management