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 Type | Description |
|---|---|
| Root user | Superuser with full privileges (UID = 0) |
| System users | Used by services (UID < 1000) |
| Normal users | Regular login users (UID โฅ 1000) |
Each user is identified by:
- Username
- UID (User ID)
- Home directory
- Login shell
3. User Account Files (Exam Important)
| File | Purpose |
|---|---|
/etc/passwd | User account details |
/etc/shadow | Encrypted passwords |
/etc/group | Group information |
/etc/gshadow | Group 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
| Command | Purpose |
|---|---|
id username | User & group IDs |
groups username | User groups |
whoami | Current user |
who | Logged-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
sudoallows 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
sudofor admin tasks
11. Advantages of User & Group Management
- Strong security
- Organized access control
- Efficient resource sharing
- Prevents unauthorized access
12. Summary Table
| Task | Command |
|---|---|
| Add user | useradd |
| Delete user | userdel |
| Modify user | usermod |
| Add group | groupadd |
| Delete group | groupdel |
| Add user to group | usermod -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.
