Commands.page Logo

What Is a Runas Alias in Ubuntu Sudoers File

This article explains the purpose and configuration of Runas aliases in the Ubuntu sudoers file. It covers how to group target users for command execution, the specific syntax required, and practical examples for implementation. Readers will gain a clear understanding of how to manage sudo privileges efficiently while maintaining system security standards.

Definition

A Runas alias defines a list of users or groups that a specific command can be executed as. While a User_Alias determines who is allowed to use sudo, a Runas_Alias determines the target identity those users can assume. This simplifies management by allowing administrators to update a single alias rather than editing multiple individual rules.

Syntax

The definition begins with the keyword Runas_Alias followed by a unique name and an equals sign. The value is a comma-separated list of usernames or group names prefixed with a percent sign. The standard format is: Runas_Alias NAME = user1, user2, %groupname

Implementation

To utilize the alias, reference its name within parentheses in the user specification rule. This tells sudo that the authorized user may run the listed commands as any user defined in the alias. For example, if DB_Alias contains postgres and mysql, the rule admin ALL = (DB_Alias) /usr/bin/db_tool allows the admin to run the tool as either database user.

Editing Safety

Always modify the sudoers file using the visudo command rather than a standard text editor. visudo locks the file to prevent concurrent edits and performs a syntax check before saving. This prevents configuration errors that could lock administrators out of sudo privileges.