Using Sudo and User Groups
For critical system changes, you typically prepend your commands with sudo. Since only the root user is allowed to modify sensitive parts of the system, sudo temporarily elevates privileges to execute commands as the superuser. A user is permitted to use sudo if they belong to the sudo group. To verify your group memberships, run:Fine-Tuning Sudo Privileges
For more granular control over user privileges, you can define specific sudo policies using the sudoers file located at/etc/sudoers. It is important not to edit this file directly; instead, always use the visudo utility. Visudo opens the file in an editor, checks for syntax errors before saving, and thus prevents misconfigurations.
Before proceeding with customization, remove Trinity from the sudo group to avoid granting her full sudo privileges:
- User/Group:
%sudoindicates that the policy applies to all users in the sudo group. - Host:
ALLspecifies that the rule applies on any host. - Run as user and group:
(ALL:ALL)means that commands can be executed as any user and any group. - Command list: The final
ALLgrants permission to execute any command.
Example Policies
To define a policy that allows Trinity to run any sudo command as any user, add an entry like this:By default, sudo commands run as root. To run a command as a different user, specify the desired user with the
-u option.ALL, the policy permits execution as any user. However, to restrict Trinity so she can only execute commands as specific users (for example, Aaron or John), list those names in the sudoers file.
Additionally, the first time a sudo command is executed in a session, it prompts for the current user’s password. The sudoers file also provides options to disable this password prompt for specific users if configured appropriately.
Always back up your sudoers file before making changes. Use the visudo utility to edit this file, ensuring that syntax errors do not lock you out of administrative privileges.