Courseiva

XK0-006 Services and User Management Practice Question

A user reports that they cannot run the command `sudo` to perform administrative tasks. The administrator checks and finds that the user is not listed in the `/etc/sudoers` file. Which command should the administrator use to safely edit the sudoers file and add the user?

⚠ Common exam trap

The trap here is assuming that any method of editing the sudoers file is acceptable, overlooking the critical safety features of visudo.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

visudo

Using `visudo` is the correct approach because it provides a safe editing environment with syntax validation and file locking. Directly editing the sudoers file or appending to it can introduce errors that break sudo. Adding a user to a group like sudo is an alternative but does not address the specific need to edit the sudoers file safely.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    echo 'username ALL=(ALL) ALL' >> /etc/sudoers

    Why it's wrong here

    Appending directly to `/etc/sudoers` with `echo` bypasses all safety mechanisms. It can easily create syntax errors or duplicate entries, and it does not lock the file. This method is dangerous and not recommended; `visudo` should be used instead to ensure the file remains valid.

  • ✓

    visudo

    Why this is correct

    `visudo` is the recommended tool for editing the `/etc/sudoers` file because it locks the file to prevent concurrent edits and performs syntax checking before saving. This reduces the risk of introducing errors that could lock out sudo access. It is the safe and standard method for modifying sudoers.

  • ✗

    usermod -aG sudo username

    Why it's wrong here

    `usermod -aG sudo username` adds the user to the sudo group, which is a valid way to grant sudo privileges on some distributions (like Ubuntu). However, the question specifies that the user is not listed in `/etc/sudoers`, and the administrator wants to edit that file safely. This command does not edit the sudoers file; it modifies group membership, which may not be the desired approach.

  • ✗

    nano /etc/sudoers

    Why it's wrong here

    Editing `/etc/sudoers` directly with a text editor like `nano` bypasses the safety checks provided by `visudo`. If a syntax error is introduced, sudo may become unusable, potentially locking out administrative access. It is strongly discouraged to edit the sudoers file directly without using `visudo`.

About these practice questions

This XK0-006 question is part of Courseiva's 781-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official CompTIA exam blueprint

This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.