Skip to content

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

useradd -m -c "Full Name" -s /bin/bash username

Options Explained

  • -m → creates home directory (e.g., /home/username)

  • -c → adds comment (usually full name)

  • -s → sets default login shell


Example

useradd -m -c "Subrat Samantaray" -s /bin/bash subrat

Explanation

  • Creates user subrat

  • Assigns /home/subrat as home directory

  • Sets default shell to Bash


Set Password for User

passwd subrat

Explanation
Assigns a password to the new user.


userdel — Delete User

Description

userdel removes a user account from the system.


Syntax

userdel -r username

Example

userdel -r subrat

Explanation

  • Deletes user subrat

  • -r removes home directory and user files


Group Management

View Group Information

cat /etc/group

Explanation
Displays all groups available on the system.


groupadd — Create New Group

groupadd groupname

Example

groupadd developers

Explanation
Creates a new group named developers.


usermod — Modify User

Description

usermod is used to modify user account properties.


Add User to Group

usermod -aG group username

Example

usermod -aG developers subrat

Explanation

  • Adds user subrat to developers group

  • -a → append (important to avoid removing existing groups)

  • -G → supplementary groups


Change Primary Group

usermod -g group username

Example

usermod -g developers subrat

Explanation
Sets developers as the primary group.


Multiple Groups Assignment

usermod -aG group1,group2 username

visudo — Edit Sudoers File Safely

Description

visudo is used to edit the /etc/sudoers file securely.


Usage

sudo visudo

Features

  • Prevents simultaneous edits

  • Checks syntax before saving

  • Avoids breaking sudo configuration


Example: Grant Sudo Access

Inside visudo:

username ALL=(ALL:ALL) ALL

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

userdel -r testuser

Important Notes

  • Root privileges are required for most commands

  • Always use -a with -G to avoid overwriting groups

  • Be careful when editing sudoers file

  • Verify changes using:

id username

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.