Courseiva
easyMultiple Choice

XK0-006 Practice Question: A junior administrator accidentally modified the…

A junior administrator accidentally modified the /etc/sudoers file and now users report not being able to use sudo. Which command should be used to safely edit the sudoers file?

⚠ Common exam trap

Many candidates think any method that writes to the file (like `echo` or `chmod`) can fix the issue, but only `visudo` provides the syntax validation and locking necessary to safely edit the sudoers file without breaking sudo.

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

The `visudo` command is the correct and safe way to edit the `/etc/sudoers` file because it locks the file against concurrent edits, performs syntax validation before saving, and prevents saving a malformed configuration that could break sudo entirely. This ensures that even if the administrator makes a mistake, the original valid file is preserved, avoiding the exact scenario described where users lose sudo access.

Answer analysis

Option-by-option breakdown

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

  • ✓

    visudo

    Why this is correct

    Editing /etc/sudoers directly risks a syntax error that locks out sudo entirely. visudo validates the file's syntax before saving and writes atomically, so a malformed edit is rejected rather than committed, satisfying the requirement to edit safely.

  • ✗

    chmod 400 /etc/sudoers

    Why it's wrong here

    chmod alters file permissions; it cannot repair malformed sudoers syntax, so sudo stays broken. Editing permissions does not validate entries. The tempting fix is locking the file down after a bad edit, but recovery requires visudo, which parses the file and refuses to save invalid syntax, preventing lockout.

  • ✗

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

    Why it's wrong here

    Appending with >> bypasses visudo's syntax and lock checks, so a malformed line can break sudo for every user. It is tempting because it adds a grant quickly, but the scenario requires repairing a corrupted sudoers file, which visudo alone validates and edits safely.

  • ✗

    usermod -aG wheel user

    Why it's wrong here

    Adding the user to the wheel group grants sudo rights but does not repair the malformed /etc/sudoers syntax that is blocking sudo. Group membership is the right fix when a valid sudoers file simply lacks an entry for that user.

About these practice questions

One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.