Linux System Administration

0 of 85 lessons complete (0%)

Managing User Accounts

Groups and the Group File

You don’t have access to this lesson

Please register or sign in to access the course content.

Unix-like operating systems, groups are used to organize and manage users with similar privileges or access rights. Each user on a Unix system belongs to one or more groups. Groups are defined in the group file, often located at /etc/group.

Here’s an overview of the group file entry:

group_name:password:GID:user_list
  1. group_name: This field contains the name of the group.
  2. password: Historically, this field used to store an encrypted password for the group. However, in modern Unix systems, it is typically left empty or contains a placeholder.
  3. GID (Group ID): This is a unique numerical identifier assigned to each group. It is used to differentiate between groups with similar names.
  4. user_list: This field contains a comma-separated list of usernames that are members of the group.

Example entry in the group file:

developers:x:1001:jane,john,mark
  • Group Name: developers
  • Password: (hashed or placeholder)
  • GID: 1001
  • User List: jane, john, mark

The purpose of groups in Unix-like systems is to provide a mechanism for managing and controlling access to files, directories, and system resources by multiple users. Groups help in organizing users and their permissions, making system administration more efficient and secure.

Key Purposes of Groups:

  1. Access Control and File Permissions:
    • Groups allow multiple users to share access to files and directories. Each file and directory in Unix-like systems has an associated owner, group, and others, with separate permissions for each.
    • File permissions are divided into three categories: owner, group, and others. The group permission applies to users who are members of the file’s assigned group.
    • For example, a file might have rwx permissions for the owner, rw- permissions for the group, and r-- for others. In this case, users in the group can read and write the file but cannot execute it.
  2. Easier User Management:
    • System administrators can manage permissions for multiple users efficiently by assigning them to a group. Instead of configuring individual permissions for each user, administrators can configure permissions at the group level.
    • For example, if multiple users need access to a shared directory, instead of modifying each user’s permissions, the administrator can assign all users to a group with appropriate permissions on the directory.
  3. Enhanced Security:
    • By grouping users, security is improved as users are granted only the access they need based on their group membership. This minimizes the risk of accidental or unauthorized access to files and system resources.
    • Certain system services or applications may restrict access to specific groups for added security (e.g., only users in the sudo group can execute commands as root).
  4. Role-Based Access:
    • Groups are often used to enforce role-based access control (RBAC). Different groups can represent different roles, such as developers, administrators, or guests, and each group can have specific permissions that align with their role.
  5. Collaboration:
    • Groups facilitate collaboration among users working on shared projects. By assigning project members to a group, they can collaborate by accessing and modifying shared files and directories.
    • For example, all members of a development team could be placed in a group that gives them read and write permissions to a directory containing project files.
  6. Privileged Access:
    • Special system groups can grant users elevated privileges. For example:
      • sudo group: Members can execute commands as the root user by using sudo.
      • wheel group: In some systems, members of this group can switch to the root user via su.
      • adm group: Users in this group can view system logs or use certain administrative tools.

How Groups Work:

Each user in a Unix-like system is assigned a primary group and can be a member of multiple supplementary groups. The primary group is typically the default group assigned when the user creates files or logs in, while supplementary groups provide additional permissions and access.

  • Primary Group: This is the default group for the user, and when the user creates files, the files belong to this group by default.
  • Supplementary Groups: A user can belong to several other groups, which allow additional access to shared files or system resources.

Example of Group Use in File Permissions:

Consider the following file permission settings on a file named example.txt:

-rw-rw-r-- 1 user1 group1 4096 Sep 14 10:00 example.txt

  • The owner user1 has read and write permissions.
  • Users in the group group1 also have read and write permissions.
  • Other users (not in the group) have only read permission.

By adding users to group1, you grant them read and write access to the example.txt file without modifying individual user permissions.

Common Groups in Unix-Like Systems:

  • users: A generic group for regular users.
  • sudo or wheel: Provides elevated privileges to its members, allowing them to run administrative commands with sudo or su.
  • adm: Used for system administration tasks like viewing logs.
  • staff: Often used for shared file access among staff or collaborators.

Group Commands

CommandPurposeKey OptionsExample
groupaddCreate a new group-g GID, -rsudo groupadd developers
groupdelDelete a groupNonesudo groupdel developers
groupmodModify a group-n new_name, -g GIDsudo groupmod -n new_group_name developers
usermodAdd user to a group or change group-aG group_name, -g group_namesudo usermod -aG developers john
getentList group informationNonegetent group developers
groupsCheck user group membershipsNonegroups john
idView user and group IDsNoneid john
gpasswdManage group membership interactively-a user, -d user, -r (remove password)sudo gpasswd -a john developers
newgrpTemporarily switch to a new groupNonenewgrp developers

This summary provides a clear view of the purpose, key options, and exampl