Commands.page Logo

How to Add a User to the Sudo Group in Ubuntu

This article provides a step-by-step guide on granting administrative privileges to a standard user account in Ubuntu by adding them to the sudo group. You will learn the specific command required to modify user group memberships, how to verify that the changes have been applied correctly, and how to test the new permissions to ensure the user can execute commands with elevated rights.

Prerequisites

To perform these actions, you must be logged in as a user that already has sudo privileges. You cannot add a user to the sudo group if your current account lacks the necessary permissions to modify system settings. Additionally, you need to know the exact username of the account you wish to modify.

Add the User to the Sudo Group

Open your terminal and execute the following command to add the desired user to the sudo group. Replace username with the actual name of the user account.

sudo usermod -aG sudo username

The -a flag ensures the user is appended to the group without being removed from other existing groups, while -G specifies the supplementary group to add. You will be prompted to enter your current password to authorize the change.

Verify Group Membership

After running the command, confirm that the user has been successfully added to the sudo group. Use the groups command followed by the username to list all groups associated with that account.

groups username

Check the output list for the word sudo. If it appears in the list, the user has been correctly assigned to the group.

Test Sudo Access

To ensure the permissions are active, switch to the user account and attempt to run a command with sudo privileges. First, switch to the user:

su - username

Once switched, try executing a command that requires administrative rights, such as updating the package list.

sudo apt update

If the command executes without a permission error and prompts for the user’s password instead of denying access, the configuration is complete. Note that if the user was already logged in during the modification, they may need to log out and log back in for the group changes to take effect in their session.