Practice Free XK0-005 Exam Online Questions
The journald entries have filled a Linux machine’s /var volume.
Which of the following is the best command for a systems administrator to use to free up the disk space occupied by these entries?
- A . journalctl –rotatejournalctl –vacuum-time=1s
- B . systemctl stop systemd-journaldsystemctl start systemd-journald
- C . rm -rf /var/log/journalsystemctl restart systemd-journald
- D . pkill -HUP systemd-journaldsystemctl restart systemd-journald
A
Explanation:
To safely reduce the size of journald logs, journalctl –rotate forces log rotation, and journalctl — vacuum-time=1s removes entries older than the specified time. This approach efficiently manages log files without directly deleting files, which could risk corruption. CompTIA Linux+ advises controlled log management for journald to avoid unintended data loss.
Reference: CompTIA Linux+ Study Guide.
A systems administrator is implementing a new service task with systems at startup and needs to execute a script entitled test.sh with the following content:
The administrator tries to run the script after making it executable with chmod +x; however, the script will not run.
Which of the following should the administrator do to address this issue? (Choose two.)
- A . Add #!/bin/bash to the bottom of the script.
- B . Create a unit file for the new service in /etc/systemd/system/ with the name helpme.service in the location.
- C . Add #!//bin/bash to the top of the script.
- D . Restart the computer to enable the new service.
- E . Create a unit file for the new service in /etc/init.d with the name helpme.service in the location.
- F . Shut down the computer to enable the new service.
B,C
Explanation:
The administrator should do the following two things to address the issue:
Add #!/bin/bash to the top of the script. This is called a shebang line and it tells the system which interpreter to use to execute the script. Without this line, the script will not run properly. The shebang line should be the first line of the script and should start with #! followed by the path to the interpreter. In this case, the interpreter is bash and the path is /bin/bash. The other option (A) is incorrect because the shebang line should be at the top, not the bottom of the script.
Create a unit file for the new service in /etc/systemd/system/ with the name helpme.service in the location. This is necessary to register the script as a systemd service and enable it to run at startup. A unit file is a configuration file that defines the properties and behavior of a service, such as the description, dependencies, start and stop commands, and environment variables. The unit file should have the extension .service and should be placed in the /etc/systemd/system/ directory. The other option (E) is incorrect because /etc/init.d is the directory for init scripts, not systemd services.
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 14: Managing Processes and Scheduling Tasks, pages 429-430.
A junior administrator is trying to set up a passwordless SSH connection to one of the servers. The administrator follows the instructions and puts the key in the authorized_key file at the server, but the administrator is still asked to provide a password during the connection.
Given the following output:
Which of the following commands would resolve the issue and allow an SSH connection to be established without a password?
- A . restorecon -rv .ssh/authorized_key
- B . mv .ssh/authorized_key .ssh/authorized_keys
- C . systemct1 restart sshd.service
- D . chmod 600 mv .ssh/authorized_key
B
Explanation:
The command mv .ssh/authorized_key .ssh/authorized_keys will resolve the issue and allow an SSH connection to be established without a password. The issue is caused by the incorrect file name of the authorized key file on the server. The file should be named authorized_keys, not authorized_key. The mv command will rename the file and fix the issue. The other options are incorrect because they either do not affect the file name (restorecon or chmod) or do not restart the SSH service (systemct1).
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 13: Managing Network Services, page 410.
A Linux administrator needs to correct the permissions of a log file on the server.
Which of the following commands should be used to set filename.log permissions to -rwxr―r–. ?
- A . chmod 755 filename.log
- B . chmod 640 filename.log
- C . chmod 740 filename.log
- D . chmod 744 filename.log
A
Explanation:
The command chmod 755 filename.log should be used to set filename.log permissions to -rwxr–r–. The chmod command is a tool for changing file permissions on Linux file systems. The permissions can be specified in octal notation, where each digit represents the permissions for the owner, group, and others respectively.
The permissions are encoded as follows:
0: no permission
1: execute permission
2: write permission
4: read permission
5: read and execute permissions (4 + 1)
6: read and write permissions (4 + 2)
7: read, write, and execute permissions (4 + 2 + 1)
The command chmod 755 filename.log will set the permissions to -rwxr–r–, which means that the owner has read, write, and execute permissions (7), the group has read and execute permissions (5), and others have read and execute permissions (5). This is the correct command to use to accomplish the task. The other options are incorrect because they either set the wrong permissions (chmod 640, chmod 740, or chmod 744) or do not exist (chmod -G).
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 11: Managing Files and Directories, page 345.
A Linux administrator needs to correct the permissions of a log file on the server.
Which of the following commands should be used to set filename.log permissions to -rwxr―r–. ?
- A . chmod 755 filename.log
- B . chmod 640 filename.log
- C . chmod 740 filename.log
- D . chmod 744 filename.log
A
Explanation:
The command chmod 755 filename.log should be used to set filename.log permissions to -rwxr–r–. The chmod command is a tool for changing file permissions on Linux file systems. The permissions can be specified in octal notation, where each digit represents the permissions for the owner, group, and others respectively.
The permissions are encoded as follows:
0: no permission
1: execute permission
2: write permission
4: read permission
5: read and execute permissions (4 + 1)
6: read and write permissions (4 + 2)
7: read, write, and execute permissions (4 + 2 + 1)
The command chmod 755 filename.log will set the permissions to -rwxr–r–, which means that the owner has read, write, and execute permissions (7), the group has read and execute permissions (5), and others have read and execute permissions (5). This is the correct command to use to accomplish the task. The other options are incorrect because they either set the wrong permissions (chmod 640, chmod 740, or chmod 744) or do not exist (chmod -G).
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 11: Managing Files and Directories, page 345.
A technician just fixed a few issues in some code and is ready to deploy the code into production.
Which of the following steps should the technician take next?
- A . Create a new branch using git checkout.
- B . Perform a git clone to pull main down.
- C . Create a git pull request to merge into main.
- D . Perform a git pull to update the local copy of the code.
C
Explanation:
After fixing issues in the code, the next step is to merge these changes into the main branch. This is typically done by creating a pull request78.
Reference:7(https://zeet.co/blog/deploy-to-production)8(https://stackoverflow.com/questions/11833511/git-deploy-to-production)
A DevOps engineer is working on a local copy of a Git repository. The engineer would like to switch from the main branch to the staging branch but notices the staging branch does not exist.
Which of the following Git commands should the engineer use to perform this task?
- A . git branch -m staging
- B . git commit -m staging
- C . git status -b staging
- D . git checkout -b staging
D
Explanation:
The git checkout -b staging command creates a new branch called staging and switches to it. This is useful when you want to create a new branch locally and begin working on it. The -b flag is used to create the branch if it doesn’t exist.
A systems administrator is checking the system logs. The administrator wants to look at the last 20 lines of a log.
Which of the following will execute the command?
- A . tail -v 20
- B . tail -n 20
- C . tail -c 20
- D . tail -l 20
B
Explanation:
The command tail -n 20 will display the last 20 lines of a file. The -n option specifies the number of lines to show. This is the correct command to execute the task. The other options are incorrect because they either use the wrong options (-v, -c, or -l) or have the wrong arguments (20 instead of 20 filename).
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 11: Managing Files and Directories, page 352.
A Linux administrator needs to analyze a failing application that is running inside a container.
Which of the following commands allows the Linux administrator to enter the running container and analyze the logs that are stored inside?
- A . docker run -ti app /bin/sh
- B . podman exec -ti app /bin/sh
- C . podman run -d app /bin/bash
- D . docker exec -d app /bin/bash
B
Explanation:
Podman exec -ti app /bin/sh allows the Linux administrator to enter the running container and analyze the logs that are stored inside. This command uses the podman tool, which is a daemonless container engine that can run and manage containers on Linux systems. The exec option executes a command inside an existing container, in this case app, which is the name of the container that runs the failing application. The -ti option allocates a pseudo-TTY and keeps STDIN open, allowing for interactive shell access to the container. The /bin/sh argument specifies the shell command to run inside the container, which can be used to view and manipulate the log files.
The other options are not correct commands for entering a running container and analyzing the logs. Docker run -ti app /bin/sh creates a new container from the app image and runs the /bin/sh command inside it, but does not enter the existing container that runs the failing application. Podman run -d app /bin/bash also creates a new container from the app image and runs the /bin/bash command inside it, but does so in detached mode, meaning that it runs in the background without interactive shell access. Docker exec -d app /bin/bash executes the /bin/bash command inside the existing app container, but also does so in detached mode, without interactive shell access.
Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 18: Automating Tasks; View container logs | Docker Docs; How to see the logs of a docker container – Stack Overflow
A systems administrator changed the file permissions on the myfile file:
$ sudo chmod g+w myfile
$ ls -l myfile
-rwxrwxr-x 1 admin editors C 2022-10-13 10:45 myfile
Then the administrator added an existing user test to the editors group:
$ sudo usermod -aG editors test
However, the user test is still unable to edit the file.
Which of the following solutions will fix this issue?
- A . The user test needs to log out and log back in before editing the myfile file.
- B . The file is only writable by the root user, and the user test needs root permissions.
- C . The group for the user test needs to be reloaded by running sudo source /etc/group.
- D . In order to edit the file, additional permissions are required that the user test does not have.