CompTIA Linux+ (XK0-006)Services and User ManagementEasy
A system administrator needs to remove a user account named `olduser` from a Linux system, including their home directory and mail spool. Which of the following commands will accomplish this task safely and completely?
- Arm -rf /home/olduser && userdel olduser
- Buserdel -r olduser
- Cuserdel olduser
- Ddeluser --remove-home olduser
Show answer & explanationAnswer & explanation
Correct answer: B. userdel -r olduser
The `userdel` command with the `-r` option (short for `--remove-home`) removes the user's home directory and mail spool along with the user account. This is the standard and safest way to completely remove a user.
Why the other options are wrong
- A. Manually removing the home directory with `rm -rf` before `userdel` is generally discouraged as `userdel -r` handles it more gracefully and ensures associated files (like mail spool) are also cleaned up systematically.
- C. This command removes the user account but leaves the home directory and mail spool intact.
- D. `deluser` is a Debian/Ubuntu-specific command. While it achieves the goal on those systems, `userdel -r` is the more universally recognized command across various Linux distributions as per CompTIA Linux+ scope.
Removing User Accounts with Home Directory
The `userdel -r` command removes a user account and their associated home directory and mail spool.
- `userdel` removes the user entry from system files.
- `-r` (or `--remove-home`) removes the home directory.
- Also removes the mail spool and other related files.
Memory trick: 'Userdel' for 'Delete', '-r' for 'Remove everything'.