User Permission Management
User Permission Management
In the Linux system, user permission management serves as the foundational infrastructure for ensuring system security and rational resource allocation. Linux employs a Role-Based Access Control (RBAC) model, defining resource ownership and operational permissions through the concepts of User and Group. Every process carries an "Effective User ID" (EUID) and a "Real User ID" (RUID), along with corresponding Effective Group ID (EGID) and Real Group ID (RGID) when executing. Understanding this mechanism is the first lesson in mastering system security and a prerequisite for subsequent configuration.
Linux provides commands such as useradd and groupadd to manage accounts. Administrators typically store user information in the /etc/passwd file, while the /etc/group file records group membership relationships. When creating regular users, it is recommended to follow the principle of least privilege, allocating only the minimum resources required for their work. For example, creating a user named alice and adding her to the developers group can simplify subsequent permission configuration:
sudo useradd -m -s /bin/bash alice
sudo groupadd developers
sudo usermod -aG developers alice
In the above commands, the -m parameter automatically creates the user's home directory, -s specifies the default login shell, and -aG indicates appending to the group list, avoiding the overwriting of existing group memberships. For system critical service accounts, tasks should be executed with elevated privileges using systemd-run or sudo, rather than running applications directly as root.
File Permissions and Access Control Model
Linux precisely controls file read, write, and execute permissions through permission bits. Each file possesses three categories of permission identifiers: owner, group, and others, represented by r/w/x for read, write, and execute permissions, respectively. For instance, if a regular text file is set to 640, only the owner can read and write, group members can read and write, and other users have no permissions:
chmod 640 /etc/important_config.txt
chown alice:developers /etc/important_config.txt
Additionally, special permission bits such as SGID (Set Group ID), SUID (Set User ID), and Sticky Bit provide finer-grained control. SGID is commonly used for shared directories to ensure newly created files automatically inherit the parent directory's group; SUID allows ordinary users to execute programs with higher privileges, often used for password tools or encryption programs.
Directory Permissions and Shared Collaboration Scenarios
In team collaboration environments, directory permission configuration is particularly critical. If multiple developers need to collaboratively edit project code, fine-grained control can be achieved by combining ACL (Access Control List). For example, setting SGID in the project root directory and restricting write access to group members only:
sudo chmod g+s /home/project/
sudo chgrp developers /home/project/
sudo chmod 750 /home/project/
The setfacl command can further define access permissions for specific users, such as allowing the bob user to view log files in read-only mode:
setfacl -m u:bob:r /var/log/app.log
This mechanism avoids security risks caused by overly permissive permissions while preventing normal collaboration due to overly strict restrictions.
Security Best Practices and Audit Recommendations
To reduce security risks, it is recommended to regularly clean up unused accounts and enable Pluggable Authentication Modules (PAM) for multi-factor authentication. For sensitive operations, the auditd system auditing tool should be enabled to record key events:
sudo auditctl -w /etc/passwd -p wa -k user_changes
Simultaneously, remote login via SSH for the root user should be prohibited, allowing access only from specific administrator IPs. All permission change operations should be logged and monitored in real-time alongside centralized log analysis platforms. Regularly reviewing abnormal behaviors in /var/log/secure and journalctl helps identify potential threats early.
Summary and Outlook
Linux's permission management system is both flexible and rigorous. By combining users, groups, file permissions, and special bits, it can construct a multi-layered security defense network. With the widespread adoption of containerization technologies and cloud-native architectures, orchestration platforms like Kubernetes have also introduced RBAC (Role-Based Access Control) models, further expanding the dimensions of permission management. Mastering these fundamental concepts will lay a solid foundation for deeply understanding modern operating system security mechanisms.