Linux System Administration: Managing Users, Groups, and Access Control

To activate the superuser account for direct interaction, a secure password must first be defined.

sudo passwd root

Transition to the root context using su:

su root
# Terminal prompt typically changes to #
exit
# Or press Ctrl+D

To switch users while landing directly in their home directory:

su - target_username

Understanding Linux Group Architecture

User groups serve as a fundamental permission abstraction layer within Unix-like systems. Instead of configuring access rights individually for every user, administrators assign privileges to a collection known as a group.

Benefits of Grouping

  • Centralized Management: Modifying permissions on a group automatically applies changes to all members.
  • Resource Sharing: Easier to grant folder access to a department rather than listing every employee ID.

System configuration files storing this data include /etc/passwd (user info) and /etc/group (group definitions). While every user has one primary group, they can belong to multiple supplementary groups simultaneously.

Core Group Management Commands

Creating and Removing Groups

Use groupadd to define a new entity. You may specify a Group ID (GID) or let the system auto-assign.

sudo groupadd engineering_team
sudo groupadd -g 500 legacy_admins

When no longer required, remove the group definition. Note that existing users belonging to this group will remain unaffected unless epxlicitly moved.

sudo groupdel engineering_team

View current group definitions:

getent group

Modifying User Membership

The usermod utility adjusts user properties. To append a user to an extra group without removing existing group memberships, use -aG.

sudo usermod -aG engineering_team deploy_bot

Other common adjustments:

  • Change Primary Group: -g <groupname>
  • Rename Login: -l <newlogin>
  • Lock Account: -L

To remove a specific user from a secondary group:

sudo gpasswd -d deploy_bot engineering_team

File Ownership and Permissions

Changing Ownership

The chown command alters who owns a file or directory. Use owner:group syntax.

sudo chown -R jenkins_user:dev_ops_group /var/build/artifacts

This recursively sets ownership for the target path.

Modifying Access Bits

Use chmod to adjust read (r), write (w), and execute (x) states. Representations can be symbolic (u+r) or numeric (octal).

Numeric Example:

sudo chmod 2750 /srv/shared_data

Breaking down the octal value 2750:

  1. Special Permissions (First digit): 2 enables Set-GID. Any new files created inside this directory inherit the parent group (dev_ops_group) instead of the creator's default group.
  2. Owner Permissions (Second digit): 7 means Read (4) + Write (2) + Execute (1).
  3. Group Permissions (Third digit): 5 means Read (4) + Execute (1).
  4. Other Users (Last digit): 0 grants no access.

Other special flags:

  • Set-UID (4): Forces execution with the owner's identity (common for Sudoers/Root binaries).
  • Sticky Bit (1): Prevents deletion of other users' files in public directories (e.g., /tmp).

Verifying Attributes

Inspect detailed metadata including ownershpi, permissions, and timestamps:

ls -ld /srv/shared_data

Switching Group Context

To start a subshell where the current group ID matches a specific membership, utilize newgrp. The target user must already be listed in the group definition.

newgrp dev_ops_group

This updates the session environment variables to reflect the new group association.

Posted on Sat, 26 Sep 2026 16:28:45 +0000 by ShashidharNP