Skip to main content

Command Palette

Search for a command to run...

Users and Permissions in Unix-like Systems

Updated
5 min read
A

I am a Student, who finds beauty in simple things. I like to teach sometimes.

In Unix-like operating systems, the management of users and their permissions is a fundamental aspect of system security and administration. This structure dictates who can access what resources and what actions they can perform.

The Root User Versus Regular Users

The root user, also known as the superuser, possesses unrestricted access to the entire system. This account can modify any file, execute any command, and alter system configurations without limitation. Its user ID (UID) is typically 0. While necessary for system administration tasks like installing software or managing hardware, operating as root for routine activities presents significant security risks. Accidental commands or malicious scripts executed by root can cause catastrophic damage.

Regular users, on the other hand, have limited privileges. Each regular user account is assigned a unique UID greater than 0 and operates within a defined set of permissions. These limitations prevent users from accessing or modifying other users' files (unless explicitly permitted) or critical system files. This principle of least privilege enhances system stability and security by containing the potential impact of errors or compromised user accounts.

Groups and User Roles

To simplify permission management for multiple users with similar access needs, Unix-like systems employ groups. A group is a collection of user accounts. Each group is identified by a group ID (GID). Users can be members of one primary group and, typically, multiple supplementary groups.

Files and directories have an owning user and an owning group. Permissions can then be set separately for the owner, the group, and others (everyone else). This allows for granular control. For example, a directory containing project files could be owned by a project lead and assigned to a group consisting of all project members, granting them read and write access while restricting access for users outside the group.

User roles are a higher-level concept often built upon the foundation of users and groups, particularly in more complex systems or applications. While the core operating system might not explicitly define "roles" in the same way as some enterprise software, administrators create de facto roles by carefully assigning users to specific groups and configuring permissions accordingly. For instance, a "web_admin" role might be realized by adding a user to the www-data group (or a similar group depending on the webserver configuration) and granting specific execute permissions on web server control scripts.

Sudo and Administrative Privileges

Sudo (superuser do) is a utility that allows permitted users to execute commands as the root user or another user, as specified in the sudoers file. This provides a mechanism for granting administrative privileges on a granular and temporary basis without requiring users to log in as root directly.

When a user prefixes a command with sudo, they are typically prompted for their own password. If the user is authorized in the sudoers file and the password is correct, the command is executed with the elevated privileges. The sudoers file, usually located at /etc/sudoers, defines which users or groups can run which commands, and as which users. It offers fine-grained control, enabling administrators to allow a user to run only specific administrative commands. For example, a junior administrator might be granted permission to restart a specific service but not to install new software.

Using sudo enhances security by:

  1. Accountability: sudo logs all commands executed through it (typically to /var/log/auth.log or a similar file), providing an audit trail of privileged operations. This is not as straightforward when multiple administrators use the shared root account.

  2. Reduced Risk: Users operate with normal privileges by default and only elevate them when necessary and for specific tasks. This minimizes the window of opportunity for accidental damage or malicious exploitation if a user's session is compromised.

  3. Password Management: Users use their own passwords to invoke sudo, avoiding the need to share the root password, which is a significant security risk.

Alternatives to Sudo

While sudo is widely adopted, several alternatives aim to provide similar functionality, often with a focus on simplicity or enhanced security.

  1. Doas (Do As): Originating from OpenBSD, doas is designed as a simpler and more lightweight alternative to sudo. Its configuration file, doas.conf, is notably more concise and arguably easier to understand than the sudoers file. The core principle is to provide sufficient privilege escalation for most common use cases without the extensive feature set (and potential complexity) of sudo. Security is a primary design goal, with a focus on a smaller codebase and thus a potentially smaller attack surface. doas allows users to run commands as another user (typically root) based on rules defined in doas.conf. It authenticates users with their own password.

  2. sudo-rs: This is a more recent project written in Rust, aiming to provide a memory-safe implementation of sudo. Memory safety vulnerabilities (like buffer overflows) have historically been a concern in C-based utilities like sudo. By leveraging Rust's memory safety features, sudo-rs seeks to eliminate this class of bugs. It aims for compatibility with existing sudoers files and plugins where feasible, potentially offering a drop-in replacement with improved security characteristics. The project also focuses on providing clear error messages and being easier to audit.

The choice of which privilege escalation tool to use depends on the specific requirements of the system and the preferences of the administrators. sudo remains the most feature-rich and widely deployed option. doas appeals to those seeking minimalism and a simpler configuration. sudo-rs presents a forward-looking option with a strong emphasis on memory safety. Regardless of the tool, the underlying principle of granting only necessary privileges for the shortest possible time remains a cornerstone of secure system administration.

More from this blog

Aman Pathak

58 posts

Things I would speak if the person in front of me is me