All CompTIA exams

Free XK0-006 practice test: 30 questions with answers

30 original questions for CompTIA Linux+, drawn from every topic area. Answer each one to see whether you got it right and why. No sign-up.

Free questions
30
Full bank
100 questions
Real exam
Maximum of 90 questions, 90 min
Passing score
720 (scale 100-900)

XK0-006 exam guide: topics, cost and format

All 30 XK0-006 questions with answers

The same questions as the test above, grouped by exam topic. Open any question to see the answer and explanation.

System Management (8 questions)

  1. Question 1

    A sysadmin needs to find every file under /var/log that is larger than 100 MB and was modified in the last 24 hours. Which command does this?

    1. Alocate --existing --limit 500 /var/log
    2. Bls -lh /var/log/ | grep -E '100M|1G'
    3. Cdu -ah --threshold=100M -d 1 /var/log
    4. Dfind /var/log -type f -size +100M -mtime -1
    Show answer and explanation
    Correct answer: D

    find combines a size test (+100M means larger than 100 MB) with a modification-time test (-mtime -1 means within the last day). ls and du do not filter by both criteria, and locate uses a database that does not check modification time this way.

  2. Question 2

    A server's root filesystem is 95 percent full. The administrator wants to see which top-level directories use the most space without crossing into other mounted filesystems. Which command is most suitable?

    1. Acat -n /etc/fstab
    2. Bdu -shx /* | sort -h
    3. Clsblk -o NAME,SIZE
    4. Dmount -av -t ext4
    Show answer and explanation
    Correct answer: B

    du with -x stays on one filesystem, and sort -h orders the human-readable sizes so the largest directories appear last. fstab lists configured mounts, mount -a mounts them, and lsblk shows block devices rather than per-directory usage.

  3. Question 3

    A new service must start automatically at boot and restart if it crashes. The systemd unit uses ExecStart for the command. Which unit file directive controls automatic restart?

    1. ARestart=on-failure
    2. BAfter=network.target only
    3. CWantedBy=multi-user.target only
    4. DUser=nobody
    Show answer and explanation
    Correct answer: A

    Restart=on-failure tells systemd to restart the service when it exits abnormally. WantedBy controls boot-time enablement, After controls ordering, and User sets the account that runs the process, so none of those restart a crashed service.

  4. Question 4

    A user reports that they cannot write to a shared directory /srv/project, which is owned by group devs with mode 2775. The user is a member of devs. What is the most likely cause?

    1. AThe directory lacks the sticky bit needed for group writes
    2. BThe directory sits on a read-only filesystem by definition
    3. CThe user's login shell is set to /bin/false by default
    4. DThe user's session has not picked up the new group membership yet
    Show answer and explanation
    Correct answer: D

    Group membership is read at login, so a session started before the user was added to devs will not have write permission through that group. The setgid bit in mode 2775 is correct for a shared directory, and the sticky bit is not what grants write access.

  5. Question 5

    An administrator needs a logical volume to grow from 20 GB to 30 GB while the filesystem stays online. The volume group has free space. Which sequence is correct for an ext4 filesystem on LVM?

    1. ARun mkfs.ext4 -F on the logical volume to reformat it at the new 30 GB size, which erases existing data
    2. BDelete the logical volume with lvremove, recreate it at 30 GB, and restore data from backup
    3. Clvextend -L +10G with the -r option to resize the filesystem, or lvextend then resize2fs
    4. DEnlarge the physical disk's partition with fdisk, which alone grows the volume
    Show answer and explanation
    Correct answer: C

    lvextend grows the logical volume, and the -r option or a following resize2fs grows the ext4 filesystem online. Deleting or reformatting the volume destroys data, and changing the physical partition alone does not extend the logical volume.

  6. Question 6

    A Linux administrator needs to find which package provides the file /usr/bin/dig on a RHEL-based system without installing anything. Which command performs this search?

    1. Arpm -evh /usr/bin/dig
    2. Bapt purge -y dnsutils
    3. Csystemctl show named
    4. Ddnf provides /usr/bin/dig
    Show answer and explanation
    Correct answer: D

    dnf provides searches the package metadata for the package that owns a file path, which answers the question without installing. rpm -e removes a package, systemctl manages services, and apt purge removes packages on Debian-based systems.

  7. Question 7

    Users complain that the system time is wrong by several minutes on a server that is otherwise healthy. Which tool shows whether time synchronization is active and which source is in use?

    1. Atimedatectl status or chronyc tracking
    2. Bnmcli -f GENERAL.STATE device show
    3. Clsof -nP -iTCP:80 -sTCP:LISTEN -u www-data
    4. Dps -eo pid,user,lstart,cmd | grep -i crond
    Show answer and explanation
    Correct answer: A

    timedatectl reports whether NTP synchronization is active, and chronyc tracking shows the selected source and offset when chrony is in use. lsof, nmcli and cron checks do not describe time synchronization.

  8. Question 8

    A process is consuming CPU and must be stopped gracefully so it can save its state. Which signal should be sent first?

    1. ASIGKILL (kill -9) immediately
    2. BSIGHUP (kill -1) to end the process
    3. CSIGTERM (kill -15)
    4. DSIGSTOP (kill -19) permanently
    Show answer and explanation
    Correct answer: C

    SIGTERM asks the process to terminate, which allows it to clean up and save state. SIGKILL cannot be caught and skips cleanup, SIGSTOP pauses rather than ends the process, and SIGHUP usually means reload or hangup, not termination.

Security (8 questions)

  1. Question 9

    A sysadmin notices that a file in a shared directory can be deleted by any user, even though it is owned by another user. Which permission setting is most likely missing from the directory?

    1. AThe sticky bit
    2. BThe setgid bit on the file
    3. CExecute permission on the file
    4. DThe setuid bit on the file
    Show answer and explanation
    Correct answer: A

    The sticky bit on a directory restricts deletion so that only the file owner, the directory owner or root can remove files, which is the typical protection for shared directories such as /tmp. The setuid and setgid bits affect execution and group inheritance, and execute permission does not control deletion.

  2. Question 10

    An administrator wants to allow a specific user to run one administrative command as root without giving them a full root shell. Which configuration should be used?

    1. ASetting the user's shell to /bin/bash and adding them to the root group
    2. BA sudoers rule that permits only that command, edited with visudo
    3. CSharing the root password with the user so they can log in as root directly
    4. DAdding the user to the root password file, /etc/shadow, as a privileged entry
    Show answer and explanation
    Correct answer: B

    A narrow sudoers rule, edited with visudo to check syntax, grants only the named command with elevated rights. Sharing the root password or granting a root shell gives far more access than needed.

  3. Question 11

    A server must accept SSH connections only from the administrator's management subnet. Which configuration achieves this at the host level?

    1. AChange the SSH port to 2222 in sshd_config and leave it open to remote sources
    2. BSet AllowUsers or Match address rules in sshd_config and restrict the firewall to that subnet
    3. CDisable the SSH daemon with systemctl and use Telnet on port 23 for remote access
    4. DGive the administrator a public IP address and open SSH to the internet globally
    Show answer and explanation
    Correct answer: B

    sshd_config can restrict users or source addresses, and a host firewall rule limits connections to the management subnet, which enforces the requirement. Changing the port is obscurity, Telnet is insecure, and a public IP does not restrict who connects.

  4. Question 12

    A file must be readable only by its owner, and the owner must be able to edit it. Which numeric permission matches this requirement?

    1. A660
    2. B600
    3. C644
    4. D777
    Show answer and explanation
    Correct answer: B

    Mode 600 gives read and write only to the owner and no access to group or others. 644 lets others read, 660 lets the group write, and 777 gives everyone full access.

  5. Question 13

    After a security review, the team finds a system account with an interactive shell that is never used by people. What is the recommended change?

    1. ASet the account's shell to /usr/sbin/nologin or /bin/false
    2. BEnable root login over SSH with PermitRootLogin yes
    3. CAdd it to the wheel group for sudo access on the host
    4. DGive the account a longer password in its home directory
    Show answer and explanation
    Correct answer: A

    Service accounts should not have interactive shells, and nologin prevents login while keeping the account for its services. A longer password or added privileges increase risk, and enabling root login over SSH is unsafe.

  6. Question 14

    A compromised host shows unexpected outbound connections. The administrator wants to see which process started each connection, including the executable path. Which command gives the best view?

    1. Acat /etc/motd and cat /etc/issue to review the login banners shown to users at each login
    2. Buptime -p and -s to show the boot time and load averages on this host
    3. Cdf -hT to list mounted filesystems and their free space on each volume in the system
    4. Dss -tnp with process information, combined with ls -l /proc/PID/exe for the path
    Show answer and explanation
    Correct answer: D

    ss -tnp shows established TCP connections with the owning process, and /proc/PID/exe links to the executable path. df, uptime and the message of the day do not show network process details.

  7. Question 15

    A Linux server was configured with SELinux in enforcing mode. A web server is denied access to a directory it needs. Which command most directly shows the reason for the denial?

    1. Acat /etc/hostname and /etc/hosts for resolution
    2. Bdf -i to list inode usage per filesystem
    3. Causearch -m avc or sealert against the audit log
    4. Dcrontab -l -u apache to list scheduled jobs
    Show answer and explanation
    Correct answer: C

    SELinux denials are recorded as AVC messages in the audit log, and ausearch -m avc or sealert summarize them with the context and suggested fix. The other commands show host names, inode usage and scheduled jobs.

  8. Question 16

    A host must allow only HTTPS and SSH inbound, and everything else must be dropped by default. The administrator uses firewalld. Which approach is correct?

    1. AKeep the default zone set to trusted and block just port 80 with a rich rule on the web tier
    2. BDisable firewalld and rely on the upstream router's NAT rules for inbound filtering
    3. COpen each port above 1024 for inbound connections from the Internet on eth0
    4. DSet the default zone to drop and allow only the https and ssh services
    Show answer and explanation
    Correct answer: D

    A default-deny zone with explicit allowances for the https and ssh services enforces the stated policy. Allowing everything and blocking one port does not meet the requirement, and relying on a router alone leaves the host open.

Scripting, Containers, and Automation (7 questions)

  1. Question 17

    A Bash script must stop at the first failing command and treat use of an unset variable as an error. Which shell options provide this behaviour?

    1. Aexport PATH=/usr/bin
    2. Bset -x only
    3. Cset -eu
    4. Dchmod +x script.sh
    Show answer and explanation
    Correct answer: C

    set -e exits when a command fails and set -u treats unset variables as errors, which makes scripts fail fast and predictably. set -x only traces commands, exporting PATH changes the search path, and chmod affects permissions rather than error handling.

  2. Question 18

    Which two commands list containers on a host that runs Podman or Docker? (Choose two.)

    1. Adocker volume create demo
    2. Bsystemctl enable docker --now
    3. Cdocker ps -a
    4. Dpodman ps
    5. Etar -czf containers.tgz /var/lib/containers
    Show answer and explanation
    Correct answer: C, D

    podman ps and docker ps -a list containers, the second including stopped ones. Creating a volume, enabling the Docker service and archiving the container storage directory do not list containers.

  3. Question 19

    A script needs to read a list of server names from a file, one per line, and run a check on each. Which loop is correct in Bash?

    1. Aecho servers.txt | run-all
    2. Bcat servers.txt | sort -r only prints the list
    3. Cwhile read -r host; do check "$host"; done < servers.txt
    4. Dfor host in servers.txt; do check $host; done only reads the file name
    Show answer and explanation
    Correct answer: C

    A while read loop redirected from the file processes each line in turn, and -r keeps backslashes literal. The for loop in the distractor iterates over the file name, and the other options print or pipe without iterating over the lines.

  4. Question 20

    A container image is built from a Dockerfile, and the team wants the final image to be as small as possible while keeping build tools out. Which approach achieves this?

    1. AInstalling every build tool and compiler into the final image for debugging
    2. BStoring secrets in an environment variable baked into the final image
    3. CUsing the latest tag on a large full-featured base image with tools
    4. DA multi-stage build that copies only the compiled artifact into a minimal base image
    Show answer and explanation
    Correct answer: D

    A multi-stage build compiles in one stage and copies only the artifact into a small runtime image, which keeps build tools and intermediate files out. Installing build tools in the final image, large base images and baked-in secrets all increase size or risk.

  5. Question 21

    An administrator needs to start a containerized web service automatically when the host boots and keep it running after failures. Which approach works on a systemd-based host with Podman?

    1. AAdd the container start command to /etc/motd so the message of the day runs it at login for every shell session
    2. BRun the container once from a shell with podman run and leave the terminal open
    3. CAdd the container to the crontab with a reboot entry and no restart policy
    4. DGenerate a systemd unit for the container with podman generate systemd or Quadlet and enable it
    Show answer and explanation
    Correct answer: D

    A systemd unit or Quadlet definition lets the container start at boot and restart on failure under systemd supervision. A message-of-the-day entry, an open terminal session and a single reboot cron entry do not supervise the service.

  6. Question 22

    A deployment script must be repeatable, and it should fail if the target host is unreachable instead of continuing silently. Which Bash approach is appropriate?

    1. ACheck the exit status of each step and exit with a non-zero code on failure
    2. BIgnore errors with 2>/dev/null on every command so output stays quiet
    3. CRun each step in the background with & and skip wait so jobs run later
    4. DPrint success before each step begins so the log shows progress
    Show answer and explanation
    Correct answer: A

    Checking exit codes and exiting non-zero on failure makes the script's result reliable for automation and CI. Hiding errors, backgrounding without waiting and printing success early all hide real failures.

  7. Question 23

    A cron job runs a script that works from a terminal but fails under cron with 'command not found'. What is the most likely cause?

    1. AThe script is written in Python, which the cron daemon cannot execute directly without a shell wrapper
    2. BCron requires scripts to be stored under /root/scripts with root ownership
    3. CCron uses a minimal environment and PATH, so the script should use full paths or set PATH
    4. DThe cron daemon requires a graphical session on the desktop, such as an X11 display or Wayland compositor
    Show answer and explanation
    Correct answer: C

    Cron runs jobs with a minimal environment, and a limited PATH often hides commands that exist in an interactive shell. Using full paths or setting PATH in the crontab fixes the issue. Python is supported by cron, and cron does not need a graphical session or special directories.

Troubleshooting (7 questions)

  1. Question 24

    A server is slow, and the administrator suspects heavy disk I/O. Which two tools help identify the cause? (Choose two.)

    1. Aip addr show
    2. Bnmcli connection up
    3. Ciotop or pidstat -d to see which processes are doing I/O
    4. Dhostnamectl set-hostname
    5. Eiostat from the sysstat package
    Show answer and explanation
    Correct answer: C, E

    iostat reports device utilization and wait times, and iotop or pidstat -d show per-process I/O, which together locate the source. Address, connection and hostname commands do not measure disk activity.

  2. Question 25

    A user cannot reach a web application by hostname but can reach it by IP address. Which two checks help find the cause? (Choose two.)

    1. AReplace the network cable to see whether the name starts working
    2. BCheck name resolution with getent hosts or dig against the configured DNS server
    3. CCheck the resolver configuration in /etc/resolv.conf or the active DNS settings
    4. DReinstall the kernel to refresh the hostname cache
    5. EChange the user's shell to see whether name lookups improve
    Show answer and explanation
    Correct answer: B, C

    getent hosts and dig test whether the name resolves through the configured resolvers, and checking resolver settings shows which servers are used. Cables, kernel reinstalls and shell changes do not affect DNS resolution.

  3. Question 26

    A service fails to start after a configuration change. Which two steps help identify the root cause? (Choose two.)

    1. ACheck the service's configuration file syntax with the program's test option when one exists
    2. BRestart the whole server immediately without reading the logs
    3. CDelete the log files so the errors are not confusing
    4. DRead the service status and recent journal entries with systemctl status and journalctl -u
    5. EDisable all security modules to see whether the service starts
    Show answer and explanation
    Correct answer: A, D

    systemctl status and journalctl show the error messages the service logged, and many daemons provide a syntax test mode that reveals configuration mistakes. Restarting blindly, deleting logs and disabling security controls do not identify the cause.

  4. Question 27

    A filesystem reports free space, but new files cannot be created. The administrator suspects the filesystem has run out of inodes. Which command confirms this?

    1. Adf -h only
    2. Bdf -i
    3. Cuptime
    4. Dfree -h
    Show answer and explanation
    Correct answer: B

    df -i reports inode totals and usage per filesystem, so a full inode table is visible even when block space remains. df -h shows block space only, free reports memory, and uptime reports load and time.

  5. Question 28

    A Linux server cannot reach the internet, but it can reach other hosts on the same subnet. Which command shows whether a default route exists?

    1. Ahostnamectl show
    2. Bcrontab -l | wc
    3. Clsblk -d -o NAME
    4. Dip route show
    Show answer and explanation
    Correct answer: D

    ip route show lists the routing table, and a missing default route explains why traffic leaving the subnet fails. The hostname, block devices and cron entries are unrelated to routing.

  6. Question 29

    A server runs out of memory and the kernel terminates a process. Which two sources help confirm which process was killed and why? (Choose two.)

    1. Admesg or the kernel log showing the OOM killer messages
    2. BThe shell history file for the root user only
    3. CThe output of ls /etc/hosts
    4. DThe contents of /etc/motd
    5. Ejournalctl -k for kernel messages around the event time
    Show answer and explanation
    Correct answer: A, E

    The kernel log records OOM killer decisions, including the process and memory usage, and journalctl -k shows those kernel messages with timestamps. Shell history, hosts entries and the message of the day do not contain this information.

  7. Question 30

    A user reports that a file on a shared volume cannot be deleted, even though they are the owner. Which two causes should be checked? (Choose two.)

    1. AThe file's name is longer than 20 characters
    2. BThe filesystem is mounted read-only
    3. CThe user's shell prompt has changed
    4. DThe file is locked by another process or has an immutable attribute set
    5. EThe file has a modification time in the future
    Show answer and explanation
    Correct answer: B, D

    A read-only mount prevents deletion regardless of ownership, and the immutable attribute set with chattr blocks changes even for owners. File name length, prompts and future timestamps do not block deletion.