CompTIA Linux+ Practice Test (XK0-005)
Use the form below to configure your CompTIA Linux+ Practice Test (XK0-005). The practice test can be configured to only include certain exam objectives and domains. You can choose between 5-100 questions and set a time limit.

CompTIA Linux+ XK0-005 (v7) Information
CompTIA Linux+ (XK0-005) Exam
The CompTIA Linux+ (XK0-005) certification is designed for IT professionals who work with Linux systems. It validates skills in system administration, security, scripting, and troubleshooting. This certification is vendor-neutral, covering multiple distributions such as Ubuntu, CentOS, and Red Hat.
Exam Overview
The XK0-005 exam consists of a maximum of 90 questions, including multiple-choice and performance-based questions. Candidates have 90 minutes to complete the test. The exam costs $358 USD. A passing score is 720 on a scale of 100 to 900. The certification is valid for three years and can be renewed through CompTIA’s continuing education program.
Exam Content
The XK0-005 exam focuses on five main domains: system management, security, scripting and automation, troubleshooting, and Linux fundamentals. System management includes package management, system monitoring, and user administration. Security covers permissions, authentication, and encryption. Scripting and automation focus on Bash scripting and task automation. Troubleshooting tests problem-solving skills for system failures and performance issues. Linux fundamentals include file system hierarchy, networking, and command-line operations.
Who Should Take This Exam?
The CompTIA Linux+ certification is ideal for system administrators, Linux support technicians, and DevOps professionals. It is recommended for individuals with at least one year of Linux experience. This certification is beneficial for IT professionals working with servers, cloud infrastructure, and cybersecurity.
How to Prepare
Candidates should review the official CompTIA Linux+ Exam Objectives and study materials provided by CompTIA. Hands-on experience with Linux systems is essential. Practice exams can help assess readiness and identify weak areas. Using Linux in a lab or virtual environment can provide practical experience with commands, system configuration, and troubleshooting.
Summary
The CompTIA Linux+ (XK0-005) certification is a valuable credential for IT professionals working with Linux systems. It validates essential skills in system administration, security, and automation. This certification is ideal for those managing Linux-based environments in IT infrastructure, cybersecurity, and cloud computing.

Free CompTIA Linux+ XK0-005 (v7) Practice Test
- 20 Questions
- Unlimited
- System ManagementSecurityScripting, Containers, and AutomationTroubleshooting
A custom service runs a preparation script in ExecStart and a cleanup script in ExecStop. The preparation script exits with status code 2, so systemd marks the service as failed and skips cleanup on stop. Which setting added to the unit file will treat exit code 2 as normal and permit the cleanup script to run?
Restart=on-failure
ValidExitCodes=*
Type=forking
SuccessExitStatus=2
Answer Description
Systemd considers any non-zero exit status a failure by default, so ExecStop commands are skipped after a failed start. The SuccessExitStatus directive overrides this behavior by listing exit codes that should be regarded as clean exits. Adding SuccessExitStatus=2 makes code 2 a normal exit, allowing the service to stop cleanly and execute ExecStop. Restart=on-failure would restart the unit rather than adjust success criteria. Changing the Type does not affect acceptable exit codes. ValidExitCodes is not a valid directive.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the SuccessExitStatus directive do in systemd?
What is the purpose of the ExecStop directive in systemd unit files?
Why is the Restart=on-failure setting not suitable in this scenario?
What is the state of a Linux process that has completed execution but still has an entry in the process table?
Sleeping
Stopped
Running
Zombie
Answer Description
A process that has completed execution but still has an entry in the process table is in the 'zombie' state. This occurs when a process has finished running, but its parent has not yet called wait() to read the child's exit status, leaving an entry in the process table as a 'zombie' that needs to be reaped. This is why the 'zombie' state is also sometimes referred to as a 'defunct' process. The other options are incorrect: 'running' is when a process is actively being executed; 'sleeping' is when a process is waiting for a resource or event; 'stopped' is when a process has been paused, typically by a signal, not when it has finished execution.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What happens if a zombie process is not reaped?
How can you identify zombie processes on a Linux system?
How can zombie processes be resolved if they persist?
A systems administrator needs to download a critical security patch from a vendor's website. The download link is http://vendor.com/downloads/patch.cgi?id=9a4f2, which saves the file with a non-descriptive name. To maintain clarity in the local /tmp/patches directory, the administrator wants to save the file as vendor_patch_2025-10-07.tar.gz directly during the download. Which of the following commands will achieve this?
wget --output-file=/tmp/patches/vendor_patch_2025-10-07.tar.gz http://vendor.com/downloads/patch.cgi?id=9a4f2
wget -O /tmp/patches/vendor_patch_2025-10-07.tar.gz http://vendor.com/downloads/patch.cgi?id=9a4f2
wget --save-as /tmp/patches/vendor_patch_2025-10-07.tar.gz http://vendor.com/downloads/patch.cgi?id=9a4f2
wget --download-as /tmp/patches/vendor_patch_2025-10-07.tar.gz http://vendor.com/downloads/patch.cgi?id=9a4f2
Answer Description
The correct command uses the wget -O option. The -O (short for --output-document) flag writes the downloaded content to a specified file. In this scenario, it saves the patch with the desired descriptive filename vendor_patch_2025-10-07.tar.gz instead of the original, non-descriptive name from the URL. The --output-file option is incorrect because it redirects log messages from wget to a file, rather than saving the downloaded content. The --save-as and --download-as options are not valid for the wget command.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the wget command?
What does the -O option in wget do?
How does wget differ from curl when downloading files?
In the process of deploying a new virtual machine that hosts an Apache web server, a Linux administrator has opened port 80 on the server's firewall and added the host record to DNS. From a workstation on a different subnet, the administrator now needs to verify two things: (1) that the web daemon is actually bound to TCP port 80 on the new server, and (2) that the port can be reached end-to-end across the network. The administrator prefers to perform both checks with a single command-line tool that requires no configuration changes on the remote host. Which command should be used?
netstat -tuln | grep ':80'
nmap -p 80 remote_server_ip
openssl s_client -connect remote_server_ip:80
dig remote_server_ip -p 80
Answer Description
The nmap command can test connectivity to a specific TCP port on a remote host and report whether that port is open. By specifying the -p option with 80 (the default HTTP port) and the target's IP address, nmap sends the necessary probe packets and interprets the response, confirming both that the service is listening and that the port is reachable. openssl s_client focuses on initiating an SSL/TLS handshake; when pointed at an unencrypted HTTP port it typically hangs or errors, so it is not ideal for simple port-reachability tests. netstat displays sockets on the local system only and cannot interrogate a remote host. dig is used for DNS lookups, not for checking open ports.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the -p option in nmap do?
Why can't openssl s_client be used to test HTTP ports?
How does nmap confirm if a port is reachable?
Which invocation will display the free capacity of the /var filesystem strictly in gigabyte units?
--si /var
-h /var
-m /var
-BG /var
Answer Description
Using the block-size option with a gigabyte parameter forces output into gigabyte units; other options either mix units, use megabytes, or apply SI prefixes variably. Specifically, the chosen invocation prints sizes with a “G” suffix for clarity.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the block-size option do in Linux commands?
What is the difference between -h and -BG options in df?
Why is it useful to display file system capacity strictly in gigabytes?
A system administrator is tasked with allowing incoming connections to a web server hosted on Linux. The server needs to accept traffic on port 443. How should the administrator configure UFW to achieve this?
ufw allow 443/tcp
ufw deny 443/tcp
ufw allow 80/tcp
ufw allow 443/udp
Answer Description
The correct answer is ufw allow 443/tcp because it allows incoming TCP traffic on port 443, which is the standard port for HTTPS traffic. ufw allow 80/tcp is incorrect because it opens port 80 (HTTP), not 443. ufw deny 443/tcp explicitly blocks the required traffic. Finally, ufw allow 443/udp permits UDP on 443, whereas HTTPS relies on the TCP protocol.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
Why does HTTPS use port 443?
What is the difference between TCP and UDP?
What is UFW and how does it work?
During a routine security audit, Bob discovers that developers have been adding SSH keys to the running ssh-agent without specifying a lifetime, leaving the keys resident indefinitely. To reduce risk, Bob wants any key he adds to be purged from the agent automatically one hour after it is loaded. Which ssh-add option should he use to set a one-hour lifetime?
ssh-add -t 3600
ssh-add -T 3600
ssh-add -x 3600
ssh-add -X 3600
Answer Description
ssh-add -t 3600 adds the private key to the agent with a maximum lifetime of 3 600 seconds (one hour). When that time elapses, the agent removes the key automatically-whether or not the key has been used-thereby limiting the window in which the credential is available.
-Ttests that a given public key matches a private key already in the agent; it does not set a lifetime.-xlocks the agent with a passphrase, preventing further use of stored keys.-Xunlocks a previously locked agent. None of these alternatives schedule automatic key removal.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `-t` option in `ssh-add` do?
How does `ssh-add` differ from simply adding an SSH key to a config file?
What is the purpose of `ssh-agent` in conjunction with `ssh-add`?
An administrator wants to conduct an aggressive scan to retrieve version information, run default scripts, and to detect the operating system of the target device. Which Nmap command option should be used?
-sn
-o
-A
-p-
Answer Description
The '-A' option in Nmap enables aggressive scanning, which combines OS detection, version detection, script scanning, and traceroute. This thorough scanning option is informative for deep network analysis. The '-sn' option is for ping scanning (host discovery), '-p-' scans all 65535 ports, and '-o' is an invalid option as it lacks the specifics for output files like '-oN' or '-oX'.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is Nmap used for?
What does the '-A' option do during an Nmap scan?
How is '-p-' different from the default port scanning in Nmap?
A system administrator needs to ensure a specific service starts automatically on system boot. Which of the following systemctl subcommands would allow the administrator to achieve this?
start
reload
status
enable
Answer Description
The correct answer is enable. The systemctl enable command is used to create a set of symlinks, so the specified unit is started automatically during the boot process. start only initiates the service immediately but does not configure it to start on boot. status provides the current status of the unit and does not modify its startup behavior. reload is used to re-read the configuration of a service without interrupting its operation.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between 'enable' and 'start' in systemctl?
How does systemctl 'enable' work behind the scenes?
What is the role of 'reload' in systemctl?
An administrator wants to prevent users from creating hard links to a certain sensitive file on a Linux system. Which command should the administrator use to achieve this security measure?
setfacl -m u:user:--- /path/to/file
chmod 700 /path/to/file
chattr +i /path/to/file
chattr +a /path/to/file
Answer Description
The correct answer is chattr +i /path/to/file. The chattr command changes the file attributes on a Linux file system. The +i attribute makes a file immutable, which means that the file can neither be modified nor deleted, and new links cannot be created to it. This is an advanced method for securing files that are not commonly modified but are critical to system security. The incorrect options either do not directly apply to the prevention of hard link creation, use an incorrect attribute, or are unrelated to file attributes.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the 'chattr' command do in Linux?
What is an immutable file in Linux?
How do hard links to files work in Linux?
If a system administrator wants to update the GRUB2 boot loader on a system that uses BIOS, which command should be used to ensure GRUB2 is properly installed onto the Master Boot Record (MBR)?
grub2-updategrub2-install /dev/sdagrub2-mkconfig -o /boot/grub2/grub.cfgupdate-grub
Answer Description
The grub2-install command is used to install the GRUB2 bootloader to the MBR when a system is using BIOS firmware. This command is critical when repairing or reconfiguring the GRUB2 installation. The grub2-mkconfig command generates a new GRUB2 configuration file based on the current system settings, but does not install GRUB to the MBR. There is no such command as grub2-update, and while update-grub is a wrapper script commonly found in Debian-based Linux distributions that calls grub2-mkconfig, it is not the correct command for installing GRUB2 to the MBR.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between GRUB2 and MBR?
What happens if the GRUB2 configuration file is updated but the bootloader is not reinstalled to the MBR?
Why is the `update-grub` command not used for installing GRUB2 in the MBR on certain systems?
Which command using a stream editor edits /var/log/payments.log in place, creates a backup with a .bak extension, and replaces every uppercase alert tag with a less alarming label?
awk '{gsub(/ISSUE/,"NOTICE"); print}' /var/log/payments.log > /var/log/payments.log.bak
sed 's/ISSUE/NOTICE/g' /var/log/payments.log > /var/log/payments.log.bak
sed -i.bak 's/ISSUE/NOTICE/g' /var/log/payments.log
perl -pi -e 's/ISSUE/NOTICE/g/' /var/log/payments.log
Answer Description
The -i.bak option tells the stream editor to modify the file directly and save the original with a .bak suffix. The s/ISSUE/NOTICE/g pattern performs a global replacement of every alert tag. Redirecting output without -i would not alter the original file, omitting the backup suffix would leave no saved copy, and awk or perl solutions either lack built-in backup support or use different syntax for backup creation.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the '-i.bak' option in the 'sed' command do?
What is the function of the 's/ISSUE/NOTICE/g' pattern used in 'sed'?
Why is 'awk' or 'perl' not suitable for this task compared to 'sed -i.bak'?
What command from the net-tools suite is traditionally used to configure network interfaces on Linux systems?
ifconfig
iwconfig
hostname
netstat
Answer Description
The correct answer is ifconfig. The ifconfig command is one of the most commonly used programs from the net-tools suite for network interface configuration. In its basic form, it allows users to configure, manage, and query the settings of network interfaces. It's important to note that while ifconfig is still used on many systems, it is considered deprecated in favor of the more modern ip command from the iproute2 suite. The other answers are not correct because netstat is mainly used for displaying network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. iwconfig is used to configure wireless network interfaces, and hostname is used to show or set the system's host name, not to manage network interfaces.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
Why is the 'ifconfig' command considered deprecated?
What is the difference between the 'ifconfig' and 'ip' commands?
What does the net-tools suite include besides 'ifconfig'?
An administrator is attempting to run a graphical network-configuration utility with elevated privileges on a desktop Linux system that uses PolicyKit. The administrator must ensure that PolicyKit rules are enforced and that any password prompt appears in a graphical dialog. Which command should be used to start the tool?
sudo network-configuration-tool
pexec network-configuration-tool
polkit network-configuration-tool
pkexec network-configuration-tool
Answer Description
The correct command is pkexec network-configuration-tool. The pkexec wrapper hands the request to PolicyKit, which evaluates the defined policies and, if necessary, invokes the desktop's polkit authentication agent to display a GUI password dialog. Running sudo network-configuration-tool would bypass PolicyKit and only present a terminal prompt. polkit network-configuration-tool is invalid because polkit is the privilege framework, not a launcher. pexec is an unrelated parallel-execution utility and provides no privilege-escalation or PolicyKit integration.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is PolicyKit and how does it work?
Why is `pkexec` preferred over `sudo` for graphical tools in Linux?
What happens if PolicyKit rules are incorrectly configured or missing?
A script needs to create a temporary file in the directory from which it is executed. The script will be called by users from various locations, so hardcoding an absolute path is not feasible. To ensure the script can reliably determine its current working directory, which of the following lines would correctly assign the absolute path of the current directory to the EXEC_DIR variable?
EXEC_DIR=$(dirname $0)EXEC_DIR=$(which $0)EXEC_DIR=$(pwd)EXEC_DIR=$CWD
Answer Description
The pwd command (print working directory) returns the absolute path of the current directory. Capturing its output with command substitution $(pwd) is the standard and most reliable method for this task. The distractor dirname $0 would return the directory containing the script file itself, which is not necessarily the same as the directory it was executed from. which $0 is not a valid use of which, as which locates a command in the user's PATH, it does not operate on script paths this way. The correct shell variable for the current working directory is PWD, not CWD, making EXEC_DIR=$CWD incorrect.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does `pwd` stand for and why is it used?
What is the difference between an absolute path and a relative path?
How does `dirname $(pwd)` differ from just `pwd`?
A system administrator is creating a systemd timer to start a backup service exactly 10 minutes after the machine has finished booting. Which line belongs in the [Timer] section of the unit file to meet this requirement?
OnCalendar=*:0/10
OnUnitActiveSec=10min
OnBootSec=10min
OnActiveSec=10min
Answer Description
OnBootSec=10min is the correct directive because it triggers the timer a specified period after the system booted. OnActiveSec=10min measures time from when the timer itself is activated-typically boot, but not always if the timer is started later. OnUnitActiveSec=10min and OnCalendar=*:0/10 relate to the last activation of the associated unit and wall-clock calendar events, respectively, so they do not guarantee a delay relative to boot.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a systemd timer?
What does OnBootSec do in a systemd timer?
How does OnActiveSec differ from OnBootSec in systemd timers?
A Linux administrator is configuring a new web server to host a secure application. A new SSL/TLS certificate and a corresponding key pair have been generated. To secure the data in transit between clients and the server, the administrator must correctly configure the web server software. What is the fundamental role of the server's private key in establishing a TLS session?
It is used to decrypt data encrypted with the server's public key and to create digital signatures to prove the server's identity.
It is used by the web server to encrypt the server's public certificate before presenting it to connecting clients.
It is installed on client systems to allow them to encrypt the initial session request sent to the server.
It must be sent to the Certificate Authority (CA) during the TLS handshake to validate that the server's public certificate is authentic.
Answer Description
In a public key infrastructure (PKI) and TLS handshake, the server's private key has two primary functions. First, it is used to decrypt data that has been encrypted by a client using the server's corresponding public key (e.g., the pre-master secret in an RSA key exchange). Second, it is used to create a digital signature on parts of the handshake data, which proves to the client that the server is the legitimate owner of the public key and certificate. The private key must always be kept secret on the server.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does a private key differ from a public key in PKI?
What happens if a private key is compromised?
What is the role of digital signatures in PKI?
A Linux administrator is writing a maintenance script that locks user accounts. The current draft is:
#!/usr/bin/env bash
echo "Enter the username of the account to disable:"
____ USERNAME
usermod -L "$USERNAME"
Which built-in command should replace the blank to capture the user's keyboard input and store it in the USERNAME variable?
echogrepreadsource
Answer Description
The read builtin pauses the script, waits for input from stdin, and stores the entered text in the specified variable-in this case USERNAME. Commands such as echo only display text, source executes another file in the current shell, and grep searches existing files; none of these capture live keyboard input, making read the only appropriate choice for this task.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does the `read` command work in a shell script?
What happens if the user doesn’t enter any input when using the `read` command?
Can the `read` command be used to accept multiple inputs at once?
A systems administrator is executing a deployment script, deploy.sh, that generates output on both stdout and stderr. The administrator needs to monitor the script's progress in real-time on the terminal while simultaneously saving all output to a file named deploy.log, overwriting the file if it already exists. Which of the following commands should the administrator use?
./deploy.sh | tee -a deploy.log./deploy.sh > deploy.log 2>&1./deploy.sh | tee deploy.log./deploy.sh 2>&1 | tee deploy.log
Answer Description
The correct command is ./deploy.sh 2>&1 | tee deploy.log. Here's a breakdown of why: 2>&1 redirects the standard error (file descriptor 2) to the same location as standard output (file descriptor 1). The pipe | then takes this combined stream and sends it to the tee command's standard input. tee then does two things: it prints the stream to its standard output (the terminal) and also writes it to the specified file, deploy.log. The option ./deploy.sh > deploy.log 2>&1 redirects all output to the file, but nothing is displayed on the terminal. The option ./deploy.sh | tee deploy.log only pipes stdout to tee; stderr is not captured and will be displayed on the terminal but not written to the log file. The option ./deploy.sh | tee -a deploy.log also fails to capture stderr and incorrectly appends to the log file instead of overwriting it, as specified by the scenario.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does the 'tee' command work in Linux?
What is the difference between the '>' and '>>' operators in Linux?
What is the role of the pipe ('|') operator in Linux?
When configuring a systemd service unit file, which Type setting will only consider the service started after the process finishes initializing and explicitly signals that it is ready to accept connections or tasks?
notify
forking
simple
dbus
Answer Description
Type=notify is used for daemons that call sd_notify() to send a READY=1 message to the systemd notification socket. Systemd will not mark the service active, nor start units that depend on it, until this message is received. Type=simple is considered active immediately after the main process is forked (or execed in the case of Type=exec). Type=forking assumes the service is ready once the parent process exits. Type=dbus waits until the specified D-Bus name is acquired. Only notify relies on an explicit ready signal from the service itself.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is sd_notify() and how does it work?
How does Type=forking differ from Type=notify in systemd?
When should I use Type=simple in a systemd unit file?
Neat!
Looks like that's it! You can go back and review your answers or click the button below to grade your test.