useradd: Creates new users or updates default user information
useradd
Can specify home directory, default groups, expiration dates
Example: useradd clark (creates user with defaults)
useradd clark
-M: Don't create home directory
-M
-g: Specify primary group
-g
groupadd: Creates new groups
groupadd
Can specify group ID instead of using system default
-g: Specify custom group ID
Example: groupadd dev or groupadd -g 1200 ops
groupadd dev
groupadd -g 1200 ops
usermod: Modifies existing user accounts
usermod
Change group membership, home directory, user ID
-G: Add user to supplemental groups
-G
-u: Change user ID
-u
-d: Change home directory
-d
Example: usermod -G dev,ops -u 1300 clark
usermod -G dev,ops -u 1300 clark
groupmod: Modifies group definitions
groupmod
Change group ID or group name
-n: Change group name
-n
Example: groupmod -n dev2 dev
groupmod -n dev2 dev
userdel: Removes user accounts
userdel
-r: Also removes home directory and files
-r
Example: userdel clark
userdel clark
groupdel: Removes groups
groupdel
Important: Cannot delete a group if it's the primary group of an existing user
Must delete the user first
Example: groupdel dev2
groupdel dev2
passwd: Changes user passwords
passwd
Regular users can change their own password: passwd
Root user can change any user's password: passwd username
passwd username
Example: passwd barry
passwd barry
/etc/group: Contains all group information
/etc/group
/etc/passwd: Contains all user information (UIDs, GIDs, home directories, login shells)
/etc/passwd
Primary Group: The main group a user belongs to
Supplemental Groups: Additional groups a user can belong to
UID: User ID number
GID: Group ID number
Root user has privileges to modify any user/group
What command creates a new user in Linux?
useradd [username]
Creates a new user account
Can be used with options like -M (no home directory), -g (specify primary group)
Example: useradd -g ops -M barry
useradd -g ops -M barry
What command creates a new group in Linux?
groupadd [groupname]
Creates a new group
Use -g option to specify custom group ID
Example: groupadd -g 1200 ops (creates group with GID 1200)
What does the useradd -M option do?
useradd -M
The -M option tells useradd to NOT create a home directory for the new user, even though a default home directory path may still be listed in /etc/passwd.
What is the difference between -g and -G options in useradd/usermod?
-g: Sets the PRIMARY group (only one)
-G: Sets SUPPLEMENTAL/additional groups (can be multiple, comma-separated)
Example: usermod -G dev,ops clark (adds clark to dev and ops groups)
usermod -G dev,ops clark
What command modifies an existing user account?
usermod [options] [username]
Common options:
-G: Add to supplemental groups
Example: usermod -u 1300 -G dev,ops clark
usermod -u 1300 -G dev,ops clark
How do you change the name of an existing group?
groupmod -n [new_name] [old_name]
The -n option specifies the new name
Group ID remains the same
What command deletes a user account?
userdel [username]
Use -r option to also delete the user's home directory and files
Example: userdel -r clark (removes user AND home directory)
userdel -r clark
What is the -r option in userdel and why is it important?
The -r option removes the user's home directory and all files within it.
Without -r: User account deleted but home directory remains
With -r: Both user account and home directory are removed
Example: userdel -r username
userdel -r username
Can you delete a group that is the primary group of an existing user?
NO. You cannot delete a group if it's the primary group of an existing user. You must first delete the user, then you can delete the group.
Supplemental groups can be deleted without removing users
Command: groupdel [groupname]
groupdel [groupname]
What file contains all user account information in Linux?
Contains: username, UID, GID, home directory, default shell
View with: cat /etc/passwd
cat /etc/passwd
Format: username:x:UID:GID:comment:home_directory:shell
What file contains all group information in Linux?
Contains: group name, GID, and group members
View with: cat /etc/group
cat /etc/group
Format: groupname:x:GID:member1,member2
How do you change a user's password as root?
passwd [username]
Root can change ANY user's password
Regular users can only change their own: passwd (no username)
Example: passwd barry (root changing barry's password)
What command shows a user's UID, GID, and group memberships?
id [username]
Shows: UID (user ID), GID (primary group ID), and all groups the user belongs to
Example output: uid=1004(clark) gid=1004(clark) groups=1004(clark),1005(dev),1200(ops)
uid=1004(clark) gid=1004(clark) groups=1004(clark),1005(dev),1200(ops)
What is the difference between a primary group and supplemental groups?
Primary Group: The main group assigned to a user (only ONE), set with -g
Supplemental Groups: Additional groups a user belongs to (can be MULTIPLE), set with -G
Every user must have exactly one primary group but can have zero or more supplemental groups
What command and option would you use to create a user with a specific primary group but no home directory?
useradd -M -g [groupname] [username]
Example: useradd -M -g ops barry
useradd -M -g ops barry
If you need to change a user's home directory to /home/flash, what commands would you need?
/home/flash
Create the directory: mkdir /home/flash
mkdir /home/flash
Change ownership: chown user:group /home/flash
chown user:group /home/flash
Update user's home directory: usermod -d /home/flash username
usermod -d /home/flash username
What are the three main pairs of user/group management commands?
Create: useradd / groupadd
Modify: usermod / groupmod
Delete: userdel / groupdel
Plus: passwd for password management
Who can change passwords for any user on the system?
The root user (superuser) can change passwords for any user on the system, including their own.
Regular users can only change their own password
Root uses: passwd [username]
How do you add a user to multiple supplemental groups at once?
usermod -G group1,group2,group3 username
Use -G flag followed by comma-separated group names (no spaces)
Example: usermod -G dev,ops,admin clark
usermod -G dev,ops,admin clark
This sets the supplemental groups
What's the syntax pattern for most user/group management commands?
[command] [options] [name]
Command: useradd, usermod, userdel, groupadd, groupmod, groupdel
Options: flags like -g, -G, -M, -u, -d, -r, -n
Name: username or groupname
Example: usermod -G dev,ops clark
Last changeda month ago