Recall & Review
beginner
What is the basic command to add a new user in a bash script?
The basic command is
useradd username. It creates a new user account named 'username'.Click to reveal answer
beginner
How can you set a password for a new user in a bash script?
You can set a password by using
echo 'username:password' | chpasswd. This updates the password for 'username'.Click to reveal answer
intermediate
Why should you check if a user already exists before adding them in a script?
To avoid errors or overwriting existing accounts. Checking prevents duplicate users and script failures.
Click to reveal answer
beginner
What command removes a user and their home directory in a bash script?
Use
userdel -r username to delete the user and their home directory safely.Click to reveal answer
intermediate
How can you add a user to a group in a bash script?
Use
usermod -aG groupname username to append the user to the specified group.Click to reveal answer
Which command creates a new user account in bash?
✗ Incorrect
useradd is used to create new user accounts. passwd sets passwords, usermod modifies users, and userdel deletes users.
How do you safely delete a user and their home directory?
✗ Incorrect
userdel -r username deletes the user and their home directory. Just userdel leaves files behind.
What does the
-aG option do in usermod?✗ Incorrect
-aG appends the user to the specified groups without removing existing group memberships.
Why check if a user exists before adding in a script?
✗ Incorrect
Checking prevents creating duplicate users and avoids script errors.
Which command sets a user's password in a script?
✗ Incorrect
Using echo 'username:password' | chpasswd sets the password non-interactively in scripts.
Explain the steps to add a new user with a password and add them to a group using a bash script.
Think about safety checks and commands for user creation, password setting, and group assignment.
You got /4 concepts.
Describe how to safely remove a user and their home directory using a bash script.
Consider commands and safety checks to avoid leftover files.
You got /3 concepts.