Question 124 of 510
SecuritymediumMultiple ChoiceObjective-mapped

Quick Answer

The correct approach is to use `usermod -L username` to lock the account and `chage -E 0 username` to expire the password immediately, then run `passwd -S -a` to generate a report of all locked accounts. This works because `usermod -L` places an exclamation mark in the password hash field, preventing password-based logins, while `chage -E 0` sets the account expiration date to epoch (January 1, 1970), blocking all authentication methods including SSH keys. On the CompTIA Linux+ XK0-005 exam, this scenario tests your ability to disable accounts without deleting user data—a common administrative task that distinguishes between locking (preventing login) and expiring (forcing a password change). A frequent trap is confusing `passwd -l` (which only locks the password, not the account) with `usermod -L` (which locks the entire account). To remember the sequence, think "Lock and Expire, then Inspect"—L for `usermod -L`, E for `chage -E 0`, and I for `passwd -S -a` to inspect status.

XK0-005 Security Practice Question

This XK0-005 practice question tests your understanding of security. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

An administrator is auditing user accounts on a Linux system and finds that several users have accounts that are no longer needed. Instead of deleting the accounts immediately, the administrator wants to lock the accounts and expire the passwords so that the users cannot log in, but the home directories and files are preserved. The administrator then wants to generate a report of all locked accounts and their last login time. Which commands and steps should the administrator use?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "immediately / without restart"

    Why it matters: Time or reboot constraint — the correct answer must take effect right away without requiring a reboot or reload.

Question 1mediummultiple choice
Full question →

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

Use 'usermod -L username' and 'chage -E 0 username', then run 'passwd -S -a' to list account status

Option D is correct because it uses `usermod -L` to lock the account by placing an exclamation mark in the password hash field, and `chage -E 0` to expire the account immediately, preventing all login methods. The `passwd -S -a` command then lists the status of all accounts, showing locked accounts with their last password change date, which can be cross-referenced with `lastlog` for last login times. This combination fully meets the requirement to lock accounts, expire passwords, preserve home directories, and generate a report of locked accounts with last login information.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

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

  • Use 'usermod -L username' to lock the account, then run 'lastlog | awk -F: '{if ($1!="Username") system("passwd -S "$1)}'

    Why it's wrong here

    Locking alone does not expire password; user may still have valid password and could potentially use other methods? Actually locked account prevents login, but password is still there. The question wants both lock and expire.

  • Use 'userdel -r username' to remove the account and home directory, then run 'lastlog'

    Why it's wrong here

    This deletes the account and home directory, not preserving them.

  • Use 'passwd -e username' to expire the password, then run 'lastlog | grep -v "Never logged in"'

    Why it's wrong here

    Expiring password does not lock the account; the user can still log in if they change password.

  • Use 'usermod -L username' and 'chage -E 0 username', then run 'passwd -S -a' to list account status

    Why this is correct

    Locks the account and expires it; passwd -S -a shows status of all accounts (locked/password expired).

    Clue confirmation

    The clue word "immediately / without restart" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates often confuse password expiration (`passwd -e`) with account locking (`usermod -L`), or assume that `lastlog` alone can identify locked accounts, when in fact `passwd -S -a` is needed to show the locked status from the shadow file.

Detailed technical explanation

How to think about this question

The `usermod -L` command works by prepending an exclamation mark (`!`) to the password hash in `/etc/shadow`, making it impossible to authenticate with any password. `chage -E 0` sets the account expiration date to epoch (January 1, 1970), which effectively disables the account at the system level, preventing even SSH key-based logins. The `passwd -S -a` command reads `/etc/shadow` to display account status (e.g., `L` for locked) and the date of the last password change, which can be combined with `lastlog` output to correlate locked accounts with their last login timestamps.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A small business has 20 workstations on the 192.168.1.0/24 network and one public IP from its ISP. The router uses PAT (NAT overload) so all 20 devices share one public address using different source ports. NAT questions test whether you understand the four address terms and which direction each translation applies.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related XK0-005 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free XK0-005 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this XK0-005 question test?

Security — This question tests Security — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use 'usermod -L username' and 'chage -E 0 username', then run 'passwd -S -a' to list account status — Option D is correct because it uses `usermod -L` to lock the account by placing an exclamation mark in the password hash field, and `chage -E 0` to expire the account immediately, preventing all login methods. The `passwd -S -a` command then lists the status of all accounts, showing locked accounts with their last password change date, which can be cross-referenced with `lastlog` for last login times. This combination fully meets the requirement to lock accounts, expire passwords, preserve home directories, and generate a report of locked accounts with last login information.

What should I do if I get this XK0-005 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "immediately / without restart". Time or reboot constraint — the correct answer must take effect right away without requiring a reboot or reload.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 25, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This XK0-005 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-005 exam.