HSR Sector 6 · Bangalore +91 96110 27980 Mon–Sat · 09:30–20:30
Chapter 5 of 20 — Linux Administration
beginner Chapter 5 of 20

User Management in Linux — Permissions, Groups & sudo

By Vikas Swami, CCIE #22239 | Updated Mar 2026 | Free Course

Users and Groups — UID, GID, /etc/passwd & /etc/group

Understanding Linux user management begins with recognizing how the system uniquely identifies users and groups. Every user on a Linux system is associated with a User ID (UID), and each group is associated with a Group ID (GID). These numeric identifiers are crucial for managing permissions and access controls.

The /etc/passwd file stores essential user account information, including username, UID, GID, home directory, and default shell. Each line in /etc/passwd follows a colon-separated format:

username:x:UID:GID:User Info:Home Directory:Shell

For example:

john:x:1001:1001:John Doe:/home/john:/bin/bash

The /etc/group file similarly maintains group information, with each line containing the group name, password placeholder, GID, and list of members:

developers:x:1002:alice,bob,charlie

These files serve as the backbone of Linux user management, enabling the system to control who can access what resources, based on UID and GID associations. When a user logs in, the system references these files to determine permissions and group memberships, which influence access rights across the system.

Properly managing users and groups ensures system security and streamlined administration. For example, assigning users to appropriate groups simplifies permission management, especially when dealing with multiple users requiring access to shared resources. Administrators at Networkers Home learn how this foundational knowledge supports advanced system administration tasks.

Creating and Managing Users — useradd, usermod, userdel & passwd

Effective Linux user management involves creating, modifying, and deleting user accounts, often using command-line tools. The most common commands for these tasks are useradd, usermod, userdel, and passwd.

Creating Users with useradd

The useradd command creates a new user account with default or specified parameters. Basic syntax:

sudo useradd [options] username

For example, to create a user named alice with a home directory and default shell:

sudo useradd -m -s /bin/bash alice

This creates a home directory at /home/alice and assigns Bash as the default shell. You can specify additional options such as -c for comments or -G for supplementary groups.

Modifying Users with usermod

The usermod command updates user attributes. For example, to add alice to the sudo group:

sudo usermod -aG sudo alice

The -aG options append the user to the specified group(s) without removing existing groups. To change a user's login shell:

sudo usermod -s /bin/zsh alice

Deleting Users with userdel & passwd

The userdel command removes user accounts:

sudo userdel -r alice

The -r flag deletes the user's home directory and mail spool. To set or change a user's password, use passwd:

sudo passwd alice

This prompts for a new password, enforcing security policies like complexity requirements. Proper user management ensures secure access and simplifies administrative control, essential skills highlighted at Networkers Home.

Group Management — groupadd, gpasswd & Primary vs Secondary Groups

Managing Linux groups is fundamental to controlling access permissions. Commands like groupadd and gpasswd facilitate group creation and administration. Understanding the difference between primary and secondary groups is vital for accurate permission assignment.

Creating and Managing Groups

To create a new group, use groupadd. For example:

sudo groupadd developers

This creates a group named developers. To add users to this group, modify their account with usermod or specify groups during user creation.

Managing Group Passwords with gpasswd

The gpasswd command manages group passwords and access control. For example, to set a password for the developers group:

sudo gpasswd developers

This password allows members to perform certain privileged actions or access shared resources protected by group policies.

Primary vs Secondary Groups

Every user has a primary group, typically matching their username, specified in /etc/passwd. Secondary groups are additional groups the user belongs to, granting supplementary permissions.

Comparison table:

Aspect Primary Group Secondary Group
Definition The main group assigned at user creation Additional groups for extended permissions
Assignment Specified in /etc/passwd Added via usermod or during group management
Permissions Impact Default group ownership of files Access rights to shared resources

For example, a user with primary group john and secondary group developers can work with files owned by either group, depending on permissions. Effective group management streamlines access control, a core component of Linux user management.

File Permissions — Read, Write, Execute & Permission Notation

File permissions in Linux define who can read, write, or execute files and directories. These permissions are fundamental to maintaining system security and integrity. Understanding how to interpret and set these permissions is essential for Linux user management.

Permission Types

  • Read (r): Ability to view file contents or list directory contents
  • Write (w): Ability to modify file contents or add/remove files in a directory
  • Execute (x): Ability to run a file as a program or script, or access a directory

Permission Notation

Permissions are represented in symbolic and numeric formats. Symbolically, permissions are shown as:

rwxr-xr--

This string represents permissions for owner, group, and others respectively:

  • Owner: rwx (read, write, execute)
  • Group: r-x (read, execute)
  • Others: r-- (read only)

Numerically, permissions are represented by a three-digit octal number:

7 (rwx), 6 (rw-), 5 (r-x), 4 (r--), 3 (-wx), 2 (-w-), 1 (--x), 0 (---)

For example, chmod 754 filename sets permissions to rwxr-xr--.

Applying Permissions

Using chmod, system administrators can set permissions. For example:

chmod 644 report.txt

This grants read/write to owner, and read-only to group and others. Proper permission management prevents unauthorized access, a key aspect of Linux user management covered at Networkers Home.

chmod, chown & chgrp — Changing Permissions and Ownership

Managing file permissions involves changing ownership and modifying access rights. The commands chmod, chown, and chgrp are central to this process.

chmod — Change Mode

This command alters the permissions of files and directories. Examples include:

chmod 755 /scripts/install.sh

This grants full permissions to owner, and read-execute to others. Use symbolic notation for clarity:

chmod u+x /script/run.sh

chown — Change Ownership

This command changes the owner of a file or directory. For example:

sudo chown alice:developers /project

This sets alice as the owner and developers as the group. Changing ownership is critical when assigning responsibility or reassigning resources.

chgrp — Change Group

Modifies the group ownership of a file or directory:

sudo chgrp admins report.pdf

This is useful for managing access at the group level without altering ownership.

Comparison Table: chmod, chown & chgrp

Command Purpose Usage Example
chmod Change file permissions chmod 644 filename
chown Change file owner and group sudo chown user:group filename
chgrp Change group ownership sudo chgrp group filename

Mastering these commands ensures precise control over file access, a core component of Linux user management.

Special Permissions — SUID, SGID & Sticky Bit

Linux provides advanced permission settings through special bits that modify standard behavior. These include SUID, SGID, and the Sticky Bit, each serving specific security and operational purposes.

SUID (Set User ID)

The SUID permission allows users to execute a file with the owner's privileges, regardless of who runs it. It is represented by an rws permission on the owner’s execute position. Example:

chmod u+s /usr/bin/passwd

This allows normal users to run passwd with root privileges, enabling password changes without granting full root access.

SGID (Set Group ID)

SGID, when set on a directory, causes files created within to inherit the directory's group, facilitating collaborative workspaces. When applied to executables, it grants group-level privileges. Example:

chmod g+s /shared

Sticky Bit

The Sticky Bit restricts deletion of files within directories to their owners, even if others have write permissions. Commonly used in directories like /tmp. Example:

chmod +t /tmp

Comparison of Special Permissions

Permission Type Symbol Purpose
SUID u+s Run files with owner privileges
SGID g+s Inherit group for new files/directories
Sticky Bit +t Restrict file deletion within directory

Implementing these permissions enhances security and operational flexibility, critical to advanced Linux user management.

sudo Configuration — /etc/sudoers, visudo & Least Privilege

The sudo command enables authorized users to execute commands with elevated privileges, essential for system administration. Proper configuration of /etc/sudoers ensures secure, controlled access.

Editing /etc/sudoers with visudo

Always use visudo to edit /etc/sudoers, as it performs syntax validation to prevent errors. For example, to grant alice sudo privileges:

alice ALL=(ALL) NOPASSWD:ALL

This allows alice to execute any command as any user without password prompts. However, for security, it's recommended to grant minimal necessary privileges, aligning with the principle of least privilege.

Configuring User Privileges

To assign specific commands:

bob ALL=(ALL) /bin/systemctl restart apache2

This restricts bob to restarting the Apache service only, reducing security risks.

Best Practices

  • Always use visudo for editing /etc/sudoers
  • Grant minimal privileges necessary for task completion
  • Regularly audit sudoers configuration for security

Effective sudo management is critical for maintaining system security, and Networkers Home provides comprehensive training in such best practices.

PAM — Pluggable Authentication Modules Overview

Linux authentication is modularized through PAM, allowing administrators to customize authentication policies. PAM enables integration of various authentication methods, such as passwords, biometrics, or tokens.

Configuration files are located in /etc/pam.d/ and specify modules and their order of operation. For example, enabling two-factor authentication involves editing relevant PAM config files to include modules like pam_google_authenticator.so.

Key features include:

  • Flexible authentication methods
  • Account and session management
  • Enhanced security policies

Understanding PAM is essential for advanced Linux security configuration. Proper PAM setup ensures robust user authentication and aligns with organizational security standards.

Key Takeaways

  • Linux user management involves understanding UID, GID, and configuration files like /etc/passwd and /etc/group.
  • Commands such as useradd, usermod, userdel, and passwd are essential for managing user accounts.
  • Group management with groupadd, gpasswd, and understanding primary vs secondary groups streamline access control.
  • File permissions determine access levels; mastering chmod, chown, and chgrp is key to securing files.
  • Special permissions like SUID, SGID, and Sticky Bit enhance security and operational capabilities.
  • Proper sudo configuration using /etc/sudoers and visudo enforces least privilege and secure admin access.
  • PAM provides modular authentication, allowing flexible, secure user login policies.

Frequently Asked Questions

What is the difference between primary and secondary groups in Linux?

Primary groups are assigned at user creation and define the default group ownership of files created by the user. Secondary groups are additional groups that a user can belong to, providing supplementary permissions. Managing these groups effectively allows for granular access control, especially when sharing resources among multiple users. For example, a user may have a primary group of 'john' but also belong to 'developers' as a secondary group, granting access to shared development resources without changing ownership. Proper understanding of primary versus secondary groups simplifies permission management and enhances security.

How does sudo improve system security?

sudo allows trusted users to execute specific commands with elevated privileges without giving them full root access. Configured via /etc/sudoers, it enforces the principle of least privilege by limiting commands users can run, reducing the risk of accidental or malicious system damage. Using visudo ensures safe editing. Proper sudo configuration ensures users only have permission to perform necessary administrative tasks, making system management both secure and efficient. Learning Networkers Home offers comprehensive training on sudo best practices.

What are the common file permissions in Linux, and how do I set them?

Linux file permissions are categorized as read (r), write (w), and execute (x), assigned to owner, group, and others. To view permissions, use ls -l. To modify permissions, use chmod. For example, chmod 644 filename grants read/write to owner and read-only to others. To change ownership, use chown. Proper permission settings prevent unauthorized access and maintain system security. Mastering these commands is critical for effective Linux user management and safeguarding sensitive data. Regular permission audits ensure compliance and system integrity.

Ready to Master Linux Administration?

Join 45,000+ students at Networkers Home. CCIE-certified trainers, 24x7 real lab access, and 100% placement support.

Explore Course