Skip to content
Home ยป Managing Users and Groups

Managing Users and Groups

Managing Users and Groups in Linux


1. Introduction

Linux is a multi-user operating system, which means multiple users can work on the system at the same time.
To maintain security, organization, and controlled access, Linux uses users and groups.

๐Ÿ‘‰ User management controls who can access the system.
๐Ÿ‘‰ Group management controls what resources users can access collectively.


2. Concept of Users in Linux

Types of Users

User TypeDescription
Root userSuperuser with full privileges (UID = 0)
System usersUsed by services (UID < 1000)
Normal usersRegular login users (UID โ‰ฅ 1000)

Each user is identified by:

  • Username
  • UID (User ID)
  • Home directory
  • Login shell

3. User Account Files (Exam Important)

FilePurpose
/etc/passwdUser account details
/etc/shadowEncrypted passwords
/etc/groupGroup information
/etc/gshadowGroup passwords

Example entry in /etc/passwd:

user:x:1001:1001:/home/user:/bin/bash

4. Managing Users in Linux


4.1 Creating a User

useradd username

Create user with home directory:

useradd -m username

4.2 Setting Password

passwd username

4.3 Modifying User Account

usermod -l newname oldname
usermod -aG groupname username

4.4 Deleting a User

userdel username
userdel -r username   # remove home directory

5. Concept of Groups in Linux

A group is a collection of users that share common permissions.

Types of Groups

  • Primary group โ€“ Default group of user
  • Secondary group โ€“ Additional groups

๐Ÿ“Œ Each user belongs to one primary group and multiple secondary groups.


6. Managing Groups


6.1 Creating a Group

groupadd groupname

6.2 Adding User to Group

usermod -aG groupname username

6.3 Changing Primary Group

usermod -g groupname username

6.4 Deleting a Group

groupdel groupname

7. Viewing User and Group Information

CommandPurpose
id usernameUser & group IDs
groups usernameUser groups
whoamiCurrent user
whoLogged-in users

8. File Ownership and Groups

Files are owned by:

  • User
  • Group

Change ownership:

chown user:group file.txt

Permissions depend on user, group, and others.


9. User Privileges & sudo

  • Only root can manage users/groups
  • sudo allows limited admin access

Example:

sudo useradd student

10. Real-World Example (Server Scenario)

  • Create users for employees
  • Assign groups like developers, admins
  • Control access to /var/www
  • Use sudo for admin tasks

11. Advantages of User & Group Management

  • Strong security
  • Organized access control
  • Efficient resource sharing
  • Prevents unauthorized access

12. Summary Table

TaskCommand
Add useruseradd
Delete useruserdel
Modify userusermod
Add groupgroupadd
Delete groupgroupdel
Add user to groupusermod -aG

13. Conclusion

Managing users and groups is a fundamental security mechanism in Linux. By properly organizing users into groups and assigning permissions, Linux ensures safe, controlled, and efficient multi-user operation, especially in server environments.