0
0
Linux CLIscripting~20 mins

useradd and userdel in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
User Management Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of the useradd command with -m option?
You run the command sudo useradd -m alice on a Linux system. What does the -m option do?
ALocks the user alice account without deleting it.
BCreates a new user named alice but does not create a home directory.
CDeletes the user alice and removes the home directory.
DCreates a new user named alice and also creates a home directory for alice.
Attempts:
2 left
💡 Hint
Think about what a home directory means for a user.
💻 Command Output
intermediate
2:00remaining
What happens when you run userdel without -r?
You run sudo userdel bob on a Linux system. What happens to bob's home directory?
AThe command fails because -r is required to delete a user.
BThe user bob is deleted but the home directory remains on the system.
CThe user bob is locked but not deleted.
DThe user bob and the home directory are both deleted.
Attempts:
2 left
💡 Hint
Think about what the -r option does in userdel.
🔧 Debug
advanced
2:00remaining
Why does this useradd command fail?
You run sudo useradd -d /custom/home charlie but get an error. What is the likely cause?
Linux CLI
sudo useradd -d /custom/home charlie
AThe -d option is invalid and causes a syntax error.
BThe username charlie is already taken.
CThe home directory /custom/home does not exist and -m was not used to create it.
DYou need to use -r to create a home directory.
Attempts:
2 left
💡 Hint
Check if the home directory exists or if you need to create it.
💻 Command Output
advanced
2:00remaining
What is the effect of userdel with -r option?
You run sudo userdel -r diana. What happens?
ADeletes the user diana and removes her home directory and mail spool.
BDeletes the user diana but leaves the home directory intact.
CLocks the user diana account without deleting it.
DDeletes only the home directory but keeps the user account.
Attempts:
2 left
💡 Hint
The -r option means remove files related to the user.
🚀 Application
expert
3:00remaining
Script to add multiple users with home directories
You want to create a script that adds users named user1, user2, and user3, each with their own home directory. Which script snippet correctly does this?
Linux CLI
#!/bin/bash
for username in user1 user2 user3; do
  # Add user with home directory
  
  
  

done
Asudo useradd -m "$username"
Bsudo useradd "$username" -m
Csudo useradd --home "$username" -m
Dsudo useradd -d /home/$username
Attempts:
2 left
💡 Hint
Remember the correct order and syntax of options for useradd.