Overview¶
Linux provides commands to manage users and groups, which are essential for:
-
Access control
-
Security management
-
Multi-user environments
-
System administration
This guide covers core commands for creating, modifying, and deleting users and groups.
useradd — Create New User¶
Description¶
useradd is used to create a new user account or update default user settings.
Syntax¶
Options Explained¶
-
-m→ creates home directory (e.g.,/home/username) -
-c→ adds comment (usually full name) -
-s→ sets default login shell
Example¶
Explanation
-
Creates user
subrat -
Assigns
/home/subratas home directory -
Sets default shell to Bash
Set Password for User¶
Explanation
Assigns a password to the new user.
userdel — Delete User¶
Description¶
userdel removes a user account from the system.
Syntax¶
Example¶
Explanation
-
Deletes user
subrat -
-rremoves home directory and user files
Group Management¶
View Group Information¶
Explanation
Displays all groups available on the system.
groupadd — Create New Group¶
Example¶
Explanation
Creates a new group named developers.
usermod — Modify User¶
Description¶
usermod is used to modify user account properties.
Add User to Group¶
Example¶
Explanation
-
Adds user
subrattodevelopersgroup -
-a→ append (important to avoid removing existing groups) -
-G→ supplementary groups
Change Primary Group¶
Example¶
Explanation
Sets developers as the primary group.
Multiple Groups Assignment¶
visudo — Edit Sudoers File Safely¶
Description¶
visudo is used to edit the /etc/sudoers file securely.
Usage¶
Features¶
-
Prevents simultaneous edits
-
Checks syntax before saving
-
Avoids breaking sudo configuration
Example: Grant Sudo Access¶
Inside visudo:
Explanation
Grants full administrative privileges to the user.
Practical Workflow¶
Create User and Assign Group¶
useradd -m -c "Test User" -s /bin/bash testuser
passwd testuser
groupadd pentest
usermod -aG pentest testuser
Delete User Completely¶
Important Notes¶
-
Root privileges are required for most commands
-
Always use
-awith-Gto avoid overwriting groups -
Be careful when editing sudoers file
-
Verify changes using:
Summary Table¶
| Command | Purpose |
|---|---|
useradd |
Create user |
userdel |
Delete user |
groupadd |
Create group |
usermod |
Modify user |
cat /etc/group |
View groups |
visudo |
Edit sudo permissions |
Conclusion¶
User and group management is critical for:
-
System security
-
Access control
-
Multi-user environments
Mastering these commands ensures proper control over user privileges and system resources in Linux.