CompTIA + XK0-005 Exam Dumps & Practice Test Questions
Question 1:
A systems administrator needs to ensure that no user, other than the root account, can log into the system when the /etc/nologin file exists. Which PAM (Pluggable Authentication Module) is responsible for enforcing this restriction?
A. pam_login.so
B. pam_access.so
C. pam_logindef.so
D. pam_nologin.so
Answer: D
Explanation:
The pam_nologin.so module (Option D) is responsible for preventing non-root users from logging into the system when the /etc/nologin file exists. When this file is present, the pam_nologin.so module checks it and denies login attempts for non-root users. The file typically contains a message explaining why logins are restricted, and when it's present, the module blocks access for anyone except the root user.
Here’s why the other options are less appropriate:
A. pam_login.so:
The pam_login.so module is responsible for handling user login and authentication processes. It does not specifically control access based on the existence of the /etc/nologin file.
B. pam_access.so:
The pam_access.so module is used for controlling access based on user and host combinations, but it does not directly interact with the /etc/nologin file to prevent logins. It deals with more granular access control.
C. pam_logindef.so:
This module works with the /etc/login.defs file to set default parameters for user login configurations, but it does not address the /etc/nologin file or prevent non-root users from logging in when the file exists.
Therefore, the pam_nologin.so module is the correct choice for enforcing this restriction.
Question 2:
A systems administrator wants to prevent the nginx service from starting both automatically and manually on a Linux system. Which of the following commands will effectively accomplish this?
A. systemctl cancel nginx
B. systemctl disable nginx
C. systemctl mask nginx
D. systemctl stop nginx
Answer: C
Explanation:
The systemctl mask nginx command (Option C) is the most effective way to prevent the nginx service from starting both automatically and manually. When you mask a service using this command, it creates a symbolic link to /dev/null for the service's unit file, making it impossible to start the service even manually with systemctl start. This effectively disables the service, preventing any possibility of it starting up.
Here’s why the other options are less appropriate:
A. systemctl cancel nginx:
There is no systemctl cancel command. This is not a valid command in systemctl, so it will not accomplish the task.
B. systemctl disable nginx:
The systemctl disable nginx command disables the service from starting automatically on boot. However, it does not prevent the service from being started manually by running systemctl start nginx. To fully prevent manual and automatic starts, masking the service is necessary.
D. systemctl stop nginx:
The systemctl stop nginx command will stop the nginx service if it's currently running, but it does not prevent the service from starting again in the future (either manually or automatically). This only temporarily stops the service for the current session.
Therefore, the best option to completely prevent nginx from starting is to mask the service with systemctl mask nginx.
Question 3:
A systems administrator recently installed several RPM (Red Hat Package Manager) packages. After reviewing the installed packages, they realize that the last installed package is unnecessary and needs to be removed. Which command will achieve this?
A. dnf remove packagename
B. apt-get remove packagename
C. rpm -i packagename
D. apt remove packagename
Answer: A
Explanation:
When managing RPM (Red Hat Package Manager) packages, the most appropriate tool to manage installed packages, including removing them, is dnf. The dnf command is the default package manager on Red Hat-based distributions (such as CentOS, Fedora, and RHEL) for managing packages, including their removal.
Option A, dnf remove packagename, is the correct command for removing a package in a Red Hat-based distribution. It will uninstall the specified package, resolving the need to remove the unnecessary one.
Option B, apt-get remove packagename, is a command used for managing packages in Debian-based distributions (such as Ubuntu), not for RPM-based systems. Therefore, this option is not applicable in this case.
Option C, rpm -i packagename, is used to install an RPM package, not to remove it. The -i flag specifically stands for "install," so this is not the correct command to remove a package.
Option D, apt remove packagename, is also used in Debian-based systems for package removal, similar to apt-get remove. However, it is not relevant to RPM systems, where dnf is the proper tool for package removal.
Therefore, the correct command to remove an RPM package in a Red Hat-based system is A, dnf remove packagename.
Question 4:
A systems administrator needs to display the last 20 lines of a specific system log file. Which of the following commands will show the desired output?
A. tail -v 20
B. tail -n 20
C. tail -c 20
D. tail -l 20
Answer: B
Explanation:
The tail command is used to display the last part of files, which is particularly useful for viewing system logs. When you want to display a specific number of lines from the end of a file, you can use the -n option followed by the number of lines.
Option B, tail -n 20, is the correct command. The -n option tells tail to display the last 20 lines of the file. This is the standard way to view a specific number of lines from the end of a log file.
Option A, tail -v 20, is incorrect because -v is not a valid option for specifying the number of lines to display. The -v option is used for verbose output in some commands, but it is not related to the number of lines in the tail command.
Option C, tail -c 20, is used to display the last 20 bytes of the file, not lines. The -c option specifies the number of bytes, not lines, so this would not show the desired output in terms of lines.
Option D, tail -l 20, is also incorrect because -l is not a valid option for the tail command. The correct option for specifying the number of lines is -n, not -l.
Therefore, the correct command to display the last 20 lines of a log file is B, tail -n 20.
Question 5:
A systems administrator needs to check the network route between two IP addresses: 10.0.2.15 and 192.168.1.40. Which of the following commands should the administrator use?
A. route -e get to 192.168.1.40 from 10.0.2.15
B. ip route get 192.163.1.40 from 10.0.2.15
C. ip route 192.169.1.40 to 10.0.2.15
D. route -n 192.168.1.40 from 10.0.2.15
Answer: B
Explanation:
The correct command to check the network route between two IP addresses is ip route get. Option B uses the ip route get command to check the route to the destination address (192.168.1.40) from the source IP (10.0.2.15). This command will return the routing details, such as the next hop and network interface used for routing the traffic.
Here’s why the other options are incorrect:
A. route -e get to 192.168.1.40 from 10.0.2.15:
The syntax of this command is incorrect. The route command does not use the -e get syntax in this context, making it invalid.
C. ip route 192.169.1.40 to 10.0.2.15:
This command uses an incorrect format. The ip route command is used for modifying routes or displaying the route table, but not for checking the specific route to a destination IP with this syntax.
D. route -n 192.168.1.40 from 10.0.2.15:
The route command with the -n option displays the route table in numeric format but does not allow specifying a "from" IP. It’s not used to check the route for a specific source and destination combination in this way.
Thus, B is the correct command to check the network route.
Question 6:
A systems administrator needs to delete all files and directories listed in a file named sobelete.txt. Which of the following commands will successfully perform this task?
A. xargs -f cat toDelete.txt -rm
B. rm -d -r -f toDelete.txt
C. cat toDelete.txt | rm -frd
D. cat toDelete.txt | xargs rm -rf
Answer: D
Explanation:
The correct command to delete all files and directories listed in a file named sobelete.txt is cat toDelete.txt | xargs rm -rf (Option D). Here’s how this works:
cat toDelete.txt outputs the list of files and directories to be deleted (from the sobelete.txt file).
The pipe (|) sends this list of files to the xargs command, which then takes each file or directory and passes it to rm -rf.
The rm -rf command removes files and directories recursively and forcefully.
Here’s why the other options are incorrect:
A. xargs -f cat toDelete.txt -rm:
This command has an incorrect syntax. The xargs command is used to take the output from another command and pass it as arguments to rm. The option -f does not exist in xargs, and the placement of the commands is incorrect.
B. rm -d -r -f toDelete.txt:
This command incorrectly uses the rm command to delete the file toDelete.txt itself, rather than deleting the files listed within it. The -d, -r, and -f options are used for directory removal and forcing deletion, but they are not used correctly in this context.
C. cat toDelete.txt | rm -frd:
This command has incorrect syntax. The rm command does not take options like -frd in this order. The correct option would be -rf, not -frd.
Therefore, D is the correct and properly formatted command to delete the files and directories listed in sobelete.txt.
Question 7:
A Linux administrator wants to set the SUID (Set User ID) on a file named dev_team.txt, which currently has 744 access rights. Which of the following commands will achieve this?
A. chmod 4744 dev_team.txt
B. chmod 744 --setuid dev_team.txt
C. chmod -c 744 dev_team.txt
D. chmod -v 4744 --suid dev_team.txt
Answer: A
Explanation:
In Linux, the Set User ID (SUID) is a special file permission that allows a user to execute a file with the permissions of the file's owner, rather than the permissions of the user running the executable. To set the SUID bit, you modify the file’s permissions using the chmod command.
Option A, chmod 4744 dev_team.txt, is the correct answer. In Linux, file permissions are represented by a 4-digit octal number. The first digit represents special permissions, with 4 representing the SUID bit. The remaining digits (744) represent the standard file permissions, where 7 gives read, write, and execute permissions to the owner, and 4 gives read-only permissions to the group and others. So, this command will set the SUID bit and preserve the original permissions of 744.
Option B, chmod 744 --setuid dev_team.txt, is incorrect. There is no --setuid option in the chmod command. The correct method for setting the SUID bit involves using the octal value for SUID, not an option like --setuid.
Option C, chmod -c 744 dev_team.txt, is incorrect. The -c option in chmod only reports changes made to the file's permissions. It doesn't relate to setting the SUID bit, and this command does not modify the permissions in the way needed to set the SUID.
Option D, chmod -v 4744 --suid dev_team.txt, is incorrect. There is no --suid option in chmod. The -v option will show verbose output for changes, but the correct method to set the SUID bit is by using the octal value 4744.
Thus, the correct command is A, chmod 4744 dev_team.txt, which will set the SUID bit along with the appropriate permissions.
Question 8:
A Linux administrator needs to make both Java 7 and Java 8 available locally for developers when deploying containers. Java 8 is already installed. Which command should the administrator execute to make Java 7 available?
A. docker image load java:7
B. docker image pull java:7
C. docker image import java:7
D. docker image build java:7
Answer: B
Explanation:
When working with Docker containers, making specific versions of software available typically involves pulling the desired image from a registry such as Docker Hub. The docker image pull command is used to retrieve an image from a Docker registry and store it locally.
Option B, docker image pull java:7, is the correct answer. This command will pull the Java 7 image from the default Docker registry (Docker Hub) and make it available locally on the system. This is the correct approach to make Java 7 available for the container.
Option A, docker image load java:7, is incorrect. The docker image load command is used to load an image from a tarball (an archive file), not to pull an image from a registry. This would not be appropriate for pulling the java:7 image from Docker Hub.
Option C, docker image import java:7, is incorrect. The docker image import command is used to import an image from a tarball or other local archive, but it is not used for pulling images from a registry like Docker Hub. Therefore, this command would not work to make Java 7 available.
Option D, docker image build java:7, is incorrect. The docker image build command is used to build a Docker image from a Dockerfile. It is not used to pull or import an image that already exists in a registry.
Therefore, the correct command to make Java 7 available locally for container deployment is B, docker image pull java:7.
Question 9:
A systems administrator wants to find out which users are currently logged into a Linux system. Which command should they use to display a list of all logged-in users?
A. whoami
B. who
C. users
D. w
Answer: B
Explanation:
The who command (Option B) is used to display a list of all users currently logged into the system. It shows information such as the username, terminal, login time, and originating IP address or hostname for each active session.
Here’s why the other options are incorrect:
A. whoami:
The whoami command displays the username of the current user who is executing the command. It does not provide a list of all users logged into the system, but rather only the user who is running the command.
C. users:
The users command provides a simple list of usernames currently logged into the system, but it may not show detailed information such as login times or originating IP addresses, which who provides.
D. w:
The w command displays detailed information about logged-in users, including their username, terminal, login time, idle time, and what they are currently doing. While it provides more information than who, it is not specifically intended just to list logged-in users like who.
Thus, B is the best choice for listing all logged-in users.
Question 10:
A systems administrator needs to check the available disk space on a Linux server. Which command should they run to display the disk usage for all mounted file systems?
A. df -h
B. du -s
C. lsblk
D. mount -v
Answer: A
Explanation:
The df -h command (Option A) is used to display the disk space usage for all mounted file systems. The -h option makes the output human-readable, presenting the sizes in a more user-friendly format (e.g., MB, GB) instead of just bytes.
Here’s why the other options are incorrect:
B. du -s:
The du command shows disk usage for files and directories. The -s option summarizes the total disk usage for a directory, but it does not show the usage for all mounted file systems. It is more useful for checking the disk usage of specific directories or files, not the system-wide file system usage.
C. lsblk:
The lsblk command lists all available block devices (e.g., disks and partitions), along with their mount points. While it shows information about storage devices, it does not provide detailed disk usage information, such as how much space is used and how much is available on the file systems.
D. mount -v:
The mount command displays information about all mounted file systems, but it does not provide disk usage statistics like df -h does. The -v option simply makes the output more verbose, but it doesn’t address the disk usage.
Therefore, A is the correct command to display disk usage for all mounted file systems on a Linux system.