CompTIA · Free Practice Questions · Last reviewed May 2026
24real exam-style questions organised by domain, each with the correct answer highlighted and a plain-English explanation of why it's right — and why the others are wrong.
A Linux administrator needs to add a new user named 'jdoe' with a home directory and a bash shell. Which command accomplishes this?
usermod -m -s /bin/bash jdoe
adduser jdoe --home /home/jdoe --shell /bin/bash
useradd -m -s /bin/bash jdoe
This creates the home directory and sets the shell.
passwd -m jdoe
A security audit reveals that users can change their password without meeting complexity requirements. Which PAM module should be configured to enforce password complexity?
pam_faillock
pam_unix
pam_tally2
pam_pwquality
pam_pwquality enforces password strength rules.
An administrator wants to allow the user 'ops' to run only the command '/usr/bin/systemctl restart httpd' via sudo on a specific host 'webserver'. Which /etc/sudoers entry is correct?
ops webserver=(root) /usr/bin/systemctl restart httpd
This restricts to host webserver and runs as root.
ops ALL=(root) /usr/bin/systemctl restart httpd
ops webserver=(ALL) /usr/bin/systemctl restart httpd
ops webserver=(root) ALL
An administrator needs to allow incoming TCP traffic on port 8443 using firewalld. Which command should be used to make this change persistent?
firewall-cmd --zone=public --add-port=8443/tcp
firewall-cmd --add-service=8443/tcp --permanent
firewall-cmd --add-port=8443/tcp
firewall-cmd --add-port=8443/tcp --permanent && firewall-cmd --reload
Adds port persistently and reloads to apply.
A system is running SELinux in enforcing mode. A custom application needs to write to /var/log/app.log. The log file shows the correct context, but access is denied. What is the most likely cause?
The file context is incorrect.
The application is running in an unconfined domain.
The SELinux boolean for the application is disabled.
Many applications require a boolean to be enabled.
SELinux is in permissive mode.
Which command displays the current SELinux mode?
selinuxenabled
sestatus
setenforce
getenforce
Correct command.
Want more Security practice?
Practice this domainA Linux administrator needs to check which services are listening on TCP ports on a server. Which command should be used to replace the deprecated netstat command?
ss -tlnp
The `ss -tlnp` command uses the `-t` flag to filter only TCP sockets, `-l` to show only listening sockets, `-n` to display numeric addresses and ports without DNS resolution, and `-p` to reveal the process identifier and name. This directly replaces `netstat -tlnp` by reading socket information from the kernel’s `/proc/net/tcp` and `/proc/net/tcp6` files, satisfying the stem’s requirement to check services listening on TCP ports.
nmap localhost
ip link show
dig -t any localhost
A Linux engineer is investigating high disk I/O on a server. Which command provides disk I/O statistics including %util, await, r/s, and w/s?
iostat -x 1
iostat -x provides extended disk I/O stats including %util, await, r/s, w/s.
sar -b
vmstat 1 5
free -h
During boot, a Linux system displays a kernel panic with 'VFS: Unable to mount root fs on unknown-block(0,0)'. Which of the following is the most likely cause?
Incorrect time configuration in the BIOS
Corrupt initramfs missing a necessary kernel module for the root device
The kernel cannot mount root because the required driver is missing from initramfs.
The /etc/fstab file has an invalid filesystem type for the root partition
A defective network cable
An administrator needs to trace system calls made by a process that is misbehaving. Which command should be used to attach to the running process and display its system calls?
tcpdump -i any
ltrace -p <PID>
strace -p <PID>
strace -p attaches to a process and shows system calls.
lsof -p <PID>
A user wants to look up the mail exchange (MX) records for a domain. Which command should be used?
dig domain.com MX
dig domain.com MX queries the MX records.
ping domain.com
host -t mx domain.com
nslookup -type=mx domain.com
An administrator wants to capture network traffic on interface eth0, writing the output to a file for later analysis, without resolving hostnames. Which command accomplishes this?
tcpdump -i eth0 -r capture.pcap
tcpdump -i eth0 -w capture.pcap -n
This captures on eth0, writes to a file, and disables name resolution.
tcpdump -i any -w capture.pcap
tcpdump -n -w eth0 capture.pcap
Want more Troubleshooting practice?
Practice this domain17% of exam · 6 sample questions below
A Linux administrator wants to ensure a bash script stops execution immediately if any command fails. Which line should be added to the script?
set -x
set -u
set -e
Correct. This causes the script to exit on any command failure.
set -o pipefail
A developer is writing a Dockerfile. The application requires a configuration file that should be copied from the build context and the container should expose port 8080. Which combination of Dockerfile instructions is correct?
COPY config.txt /app/ and EXPOSE 8080
Correct. COPY copies the file, EXPOSE documents the port.
ADD config.txt /app/ and WORKDIR 8080
ADD config.txt /app/ and RUN expose 8080
COPY config.txt /app/ and CMD 8080
An administrator is writing a bash script that loops through all .log files in /var/log and prints the file name if the file is larger than 100 kilobytes. Which loop correctly implements this?
ls -l /var/log/*.log | awk '$5>100 {print $NF}'
for f in /var/log/*.log; do if [ -s $f -a $(stat -c%s $f) -gt 100 ]; then echo $f; fi; done
find /var/log -name '*.log' -size +100k -exec echo {} \;
Correct. find with -size +100k matches files larger than 100 kilobytes.
for f in /var/log/*.log; do if [ $f -gt 100k ]; then echo $f; fi; done
A team uses Ansible for configuration management. They want to ensure a service is running on all managed nodes. Which Ansible module should be used in the playbook?
systemd
service
Correct. The service module ensures a service is in the desired state.
command
shell
A Docker container is running in the background. Which command allows the administrator to execute an interactive bash shell inside the running container named 'webapp'?
docker start -i webapp
docker run -it webapp bash
docker exec -it webapp bash
Correct. Exec runs a command interactively in the running container.
docker attach webapp
In a bash script, a developer needs to parse command-line options such as -f filename and -v (verbose). Which built-in command is best suited for this task?
getopt
getopts
Correct. getopts is the built-in command for parsing options.
case
shift
Want more Automation, Orchestration, and Scripting practice?
Practice this domainA Linux administrator needs to locate all files in the /var directory that have been modified within the last 30 minutes and are larger than 10MB. Which command accomplishes this task?
find /var -mmin 30 -size +10M
find /var -mmin -30 -size +10M
Correct: -mmin -30 matches files modified less than 30 minutes ago, and -size +10M matches files larger than 10MB.
locate /var -mmin -30 -size +10M
find /var -mtime -30 -size +10M
A user reports that a script in /home/user/script.sh fails to execute. The output of 'ls -l script.sh' is '-rw-r--r-- 1 user user 1024 Apr 1 10:00 script.sh'. Which command should be used to make the script executable for all users?
chmod 644 script.sh
chmod a+x script.sh
Correct: a+x adds execute permission for all users (owner, group, others).
chmod u+x script.sh
chmod 755 script.sh
A system administrator needs to set the umask so that newly created files have permissions of 644 and directories have permissions of 755. Which umask value should be set?
0222
0022
Correct: umask 022 subtracts group and others write permission, resulting in 644 for files and 755 for directories.
000
077
An administrator wants to grant a specific user, 'jdoe', read and write access to a file that is owned by root:root with permissions 640. The administrator does not want to change the file's owner or group. Which approach should be used?
Use setfacl -m u:jdoe:rw file
Correct: ACL entry for user jdoe grants read and write without altering standard permissions.
Change file owner to jdoe
Use chmod o+rw file
Add jdoe to the root group
A user needs to view the first 15 lines of a large log file. Which command is most appropriate?
head -n 15 filename
Correct: head -n 15 shows the first 15 lines.
cat filename | head -n 15
less -N 15 filename
tail -n 15 filename
A Linux administrator wants to search for all occurrences of the word 'ERROR' in log files under /var/log, ignoring case, and also print the line numbers. Which command should be used?
grep -vi 'ERROR' /var/log
grep -rin 'ERROR' /var/log
Correct: -r recursive, -i ignore case, -n line numbers.
grep -rn 'ERROR' /var/log
find /var/log -name '*ERROR*'
Want more System Management practice?
Practice this domainThe XK0-006 exam has 90 questions and must be completed in 90 minutes. The passing score is 720/1000.
Multiple-choice and performance-based questions on Linux system administration, scripting, security, storage, and virtualisation. Some questions are performance-based (PBQs), asking you to complete tasks in a simulated environment.
The exam covers 4 domains: Security, Troubleshooting, Automation, Orchestration, and Scripting, System Management. Questions are weighted by domain — higher-weight domains appear more on your actual exam.
No. These are original exam-style practice questions written against the official CompTIA XK0-006 exam objectives. They are not copied from the real exam. Courseiva focuses on genuine understanding, not memorisation of braindumps.
Courseiva tracks your accuracy per domain and routes you toward weak areas automatically. Free, no account required.