How to Add User to Sudoers in Ubuntu


In Linux, root user is the highly privileged user that can carry out any activity such as to add/delete a user account, install/remove an application, and has access to all the commands and file. As a system administrator of Ubuntu, you may sometimes need to grant other users access to execute commands with sudo, the program that provides a secure and flexible way to run commands with super user privilege. This can be useful for various reasons, such as to allow other users to perform certain tasks that require elevated privileges or to delegate certain responsibilities to some users.

You can grant super user privileges to other users by either adding them to the sudo group or by adding the user to the sudoers file. Let’s see how to do this:

Method #1 Adding User to the sudo Group 

The simplest and quickest way to assign a user sudo privileges is to add it to the sudo group. Doing so will add the user to the sudoers list.

Open the Terminal and run the below command to assign the user sudo privileges:

$ sudo usermod -aG sudo username

For example, to add the user “amara” to the sudoers list and assign sudo privileges, the command would be:

$ sudo usermod -aG sudo amara

Method #2 Adding User to the /etc/sudoers File 

Another method to assign a user sudo privileges is to add it in the /etc/sudoers file. However, you must edit the file only using visudo and never edit the file directly using any text editor. This method validates the file syntax and prevents it from being edited by two users at the same time.

To assign the user sudo privileges, edit the /etc/sudoers file using the below command:

$ sudo visudo

Add the below line at the end of the file while replacing the username with the actual user you want to assign sudo privileges.

username ALL=(ALL:ALL) ALL

Then save and close the file.

How-Add-User-Sudoers-Ubuntu

Verify if a User Has Sudo Access

There are two ways you can verify if a user has sudo access.

One of the ways to verify if a user has sudo access is to check whether it belongs to sudo group or not. To do so, run the groups command followed by the username:

$ groups username

This command will list all the groups that a user belongs to. If the output lists the sudo group, this indicates the user belongs to the sudo group and has sudo privileges.

For example, to check if a user named “amara” belongs to the sudo group, the command would be:

$ groups amara

You can see the sudo group in the output which means user “amara” has sudo privileges.

How-Add-User-Sudoers-Ubuntu

The second way to check if a user has sudo access is to use the below command:

$ sudo -l -U username

How-Add-User-Sudoers-Ubuntu
If a user does not have sudo privileges, it will return the output like this:

How-Add-User-Sudoers-Ubuntu

In this article, we have shown you how to add a user to sudoers using two different methods. By following any of these methods, you can quickly and easily grant sudo privileges to users in Ubuntu.

Print Friendly, PDF & Email
Categories

2 Comments

Add yours

Comments are closed.