Linux Basics: User and Group Management

Introduction

In Linux systems, all operations are based on users (<span>User</span>) and user groups (<span>Group</span>). From file permissions, system logins, to service operations and security management, the user mechanism is essential.

In this article, we will delve into:

  1. The basic concepts of Linux users and user groups
  2. The system files related to user management in Linux
  3. The structure and function of the user password file

1. Basic Concepts of Linux Users and User Groups

Linux is a multi-user, multi-tasking operating system, which means multiple users can log into the system and operate independently at the same time.

Each user has a unique identity information (<span>User ID</span>) in the system and belongs to one or more user groups (<span>Group</span>).

Type Description
User The basic operational entities in the system, such as root, student, nobody, etc.
Group A collection of users used for unified permission allocation
UID (User ID) The unique identification number assigned to each user by the system
GID (Group ID) The unique identification number assigned to each group by the system
Root User The super administrator with the highest permissions in the system (UID=0)
Regular User Restricted users who can only operate within their home directory

🧩 Practical Case: View Current Logged-in Users and IDs

whoami          # Display the current logged-in username
id              # Display the current user's UID, GID, and group information
groups          # View all user groups the current user belongs to

📘 Note:

<span>whoami</span>: Tells you “who you are”
<span>id</span>: Displays detailed user identity information
<span>groups</span>: Displays group affiliations

These commands can help you quickly confirm your current login identity, which is especially useful in system management and permission debugging.

2. Files Related to Linux Users and Groups

The information about users and user groups in Linux does not exist “out of thin air”; it is stored in specific system files.

File Path Function Description
<span>/etc/passwd</span> User account information file (records username, UID, GID, home directory, Shell, etc.)
<span>/etc/group</span> User group information file (records group name, GID, and member list)
<span>/etc/shadow</span> User password file (stores encrypted passwords and password policies)
<span>/etc/gshadow</span> User group password file (records group passwords and group administrators)

🧩 Practical Case: View System User and Group Information

cat /etc/passwd        # View information of all users in the system
cat /etc/group         # View information of all user groups
cat /etc/shadow        # View encrypted user password records (readable only by root)

📘 Note: These files together form the user database of the system. Regular users can usually only view <span>/etc/passwd</span> and <span>/etc/group</span>, while <span>/etc/shadow</span> is restricted due to containing sensitive information.

💡 Tip: To quickly view which regular users exist in the system, you can use the command:

awk -F: '$3>=1000{print $1}' /etc/passwd

This command will filter out regular users with UID ≥ 1000.

3. Linux User Password File

In early Unix systems, user password information was stored in the <span>/etc/passwd</span> file, but this posed a significant security risk (as all users could read this file).

To address this issue, modern Linux systems separate the password part and store it in the <span>/etc/shadow</span> file, which is accessible only by <span>root</span>.

1️⃣ Structure of the /etc/passwd File

Each line in the <span>/etc/passwd</span> file represents a user, formatted as follows:

username:password_placeholder:UID:GID:user_description:home_directory:login_shell

For example:

student:x:1001:1001:Student User:/home/student:/bin/bash

📘 Field Explanation:

Field Meaning
Username The username used to log into the system
Password Placeholder Usually <span>x</span>, indicating that the password is stored in <span>/etc/shadow</span>
UID The unique number assigned to the user (the UID of root is 0)
GID The default group number of the user
User Description A description of the user, which can be empty
Home Directory The default path after the user logs in
Shell The command interpreter used after login (e.g., <span>/bin/bash</span>)

2️⃣ Structure of the /etc/shadow File

<span>/etc/shadow</span> file is used to store user password information and password policies:

username:encrypted_password:last_modified_time:min_days:max_days:warning_days:inactive_days:expiration_date:reserved_field

Example:

student:$6$A7xzPq...$:19370:0:99999:7:::

📘 Field Explanation:

Field Meaning
Username Corresponds to the username in <span>/etc/passwd</span>
Encrypted Password The password encrypted using algorithms like <span>SHA-512</span>
Last Modified Time The number of days since January 1, 1970
Min Days The minimum interval in days for password changes
Max Days The number of days the password is valid
Warning Days The number of days before password expiration to issue a warning
Inactive Days The number of days before the account is disabled after password expiration
Expiration Date The date when the account is completely expired
Reserved Field Currently unused

Tip: You can use <span>chage -l username</span> to view the password expiration policy for a specified user.

🧩 Practical Case: View and Modify User Password Policies

sudo chage -l student            # View password expiration information for student user
sudo chage -M 90 student         # Set the maximum password validity period to 90 days
sudo chage -W 7 student          # Issue a warning 7 days before password expiration
sudo passwd student              # Change user password

📘 Note: These commands are commonly used in servers with high security requirements, helping administrators ensure regular updates and security of account passwords.

Conclusion

In this article, we learned the core knowledge of the Linux user system:

  1. The basic concepts and differences between users and user groups
  2. The system file structure of user and group information
  3. The secure storage mechanism and policy settings of password files

Understanding these contents is the first step in mastering Linux permission management and system security.

Leave a Comment