How to Add a User to Sudo group (Sudoers) on Ubuntu

The sudo command is the preferred means to handle elevated permissions. In supported versions of Ubuntu, using the sudo command will grant elevated permissions for 15 minutes.

When installing Ubuntu, the user account that was created during the initial setup has sudo rights. However, there may be a need to add additional sudo users or to remove the access. This is a straightforward process with a few commands.

The default user account created during Ubuntu installation already has sudo rights. However, you may want to add another sudo user or remove sudo access for some. This is a straightforward process that can be done using a few commands, which will be demonstrated in this post.

This simple tutorial will show you how to add a new user to sudo group (a.k.a sudoers) in order to provide sudo access for it.

Prerequisites

  • Operating system: Any Ubuntu release, preferably the latest version.
  • An user account which already has root access or the root user itself.

Before following the process, it is recommended that you make sure your Ubuntu-based system is up-to-date by running the following command:

sudo apt update && sudo apt upgrade

Create a new User Account on Ubuntu

The first thing you want to do is adding a new user account. Every user has their own home folder, documents, and settings. You will need administrator privileges to add user accounts.

First, create the user account demo_user by running the following command. Remember to replace demo_user with your desired account name.

sudo adduser demo_user

Right after pressing the Enter key, you will be asked to input your password along with other information. Except for the password, all other info such as name, phone numbers, etc. are optional, and can be skipped by pressing Enter.

Add New User To Sudoers/Sudo Group

The next thing we want to do is adding the new user to the sudo group so that it has sudo privileges. This can be done using the following command:

sudo usermod -aG sudo demo_user

Remember to replace demo_user with your desired account name.

It is recommended to check if the username was successfully added to the sudoers group using the id command:

id demo_user

Once you see something like uid=-xxx gid=xxx groups=xxx(demo_user), xxx(sudo), then the user has been successfully added to the sudo group.

Alternatively, you can run groups command to find out which groups an user belong to. For example:

groups demo_user

Verify Sudo Access

Now that you have added the user to the sudo group, it is time to test the account. This can be done by actually logs into the account using the su command followed by the username like so:

su demo_user

If the command runs successfully, you have successfully added a new username to the sudoers group.

We hope that the short article provide helpful information on how to add a User to Sudoers/Sudo group on Ubuntu. You may want to check out our other tutorials for Ubuntu such as chown "operation not permitted" error, How to Hibernate in Ubuntu, set up an Ubuntu-based NAS – LinuxPip and   Install OpenSSL in Ubuntu – LinuxPip

If you have any question, don’t hesitate to let us know in the comment section below.

Click to rate this post!
[Total: 0 Average: 0]

Leave a Comment