0
0
Bash Scriptingscripting~5 mins

User account management script in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Apasswd
Buseradd
Cusermod
Duserdel
How do you safely delete a user and their home directory?
Arm -rf /home/username
Buserdel username
Cuserdel -r username
Ddeluser username
What does the -aG option do in usermod?
AAdds user to a group without removing from others
BDeletes user from a group
CCreates a new group
DChanges user's primary group
Why check if a user exists before adding in a script?
ATo avoid duplicate users and errors
BTo speed up the script
CTo delete old users
DTo change the password
Which command sets a user's password in a script?
Apasswd username
Buseradd -p password username
Cusermod -p password username
Decho 'username:password' | chpasswd
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.