USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

User and Group Management

Lesson 9/40 | Study Time: 20 Min

User and group management is a fundamental aspect of Linux system administration, essential for maintaining system security, organizing permissions, and controlling access to resources. Linux, being a multi-user system, requires precise management of user accounts, groups, and privileges.

The key commands for user management include useradd, usermod, and userdel for creating, modifying, and deleting users. For groups, groupadd, groupmod, and groupdel are used. Additionally, configuring sudo privileges and managing privilege escalation are critical components of secure system operation.

Proper user and group management ensures that users have appropriate access rights, helps implement the principle of least privilege, and prevents unauthorized system activity, which is vital in professional computing environments.

User Account Management

Effective user management ensures proper access control and system security. The list below demonstrates common commands used to manage Linux user accounts.


1. Creating Users: The useradd command creates new user accounts.

Example:

bash
sudo useradd -m -s /bin/bash alice


-m: creates the home directory.

-s: sets the login shell.

User details are stored in /etc/passwd, with sensitive data like encrypted passwords in /etc/shadow.


2. Modifying Users: Use usermod to edit user properties such as username, home directory, login shell, and group memberships.

Example:

bash
sudo usermod -l newusername oldusername # change username
sudo usermod -d /new/home/dir -m username # move home directory
sudo usermod -s /bin/zsh username # change shell


3. Deleting Users: The userdel command removes user accounts.

Example:

bash
sudo userdel -r username


-r: removes the user’s home directory and mail spool.

Group Management

Proper group management helps organize users and control shared access to resources. The list below demonstrates common group-related administrative tasks.


1. Creating Groups: Create new groups using groupadd.

Example:

bash
sudo groupadd developers


2. Modifying Groups: Change a group’s name or GID with groupmod.

Example:

bash
sudo groupmod -n newgroupname oldgroupname
sudo groupmod -g 1050 developers


3. Deleting Groups: Remove groups with groupdel.

Example:

bash
sudo groupdel developers


4. Managing Group Membership

Add users to supplementary groups to grant additional permissions:

bash
sudo usermod -aG groupname username


1. The -a option appends without removing the user from existing groups.

2. To remove a user from a group, use gpasswd -d username groupname.

Sudo Configuration and Privilege Escalation

The sudo command allows authorized users to execute commands with elevated privileges securely. Configuration is done via the /etc/sudoers file or included configuration snippets, edited safely with visudo.


1. Adding a user to the sudo group:

bash
sudo usermod -aG sudo username


2. Fine-grained sudo permissions can allow specific command execution without full root access.