How to add a user to the sudoers file for superuser privileges

Linux is a multi-user operating system, which means, multiple users can use a single computer for different purposes. However, there is an administrator who has control over the privileges of the users, using the operating system or the computer. However, just like Windows, you can sometimes get administrator privileges to carry out certain activities, just the same way we all use the ‘Run as administrator’ option, with certain applications on Windows. On Linux systems, as well you can execute certain commands, or applications with administrator privileges with the sudo keyword before the command that you want to execute. 

However, on Linux each time you want to get administrator privileges, you are actually asking for Superuser privileges. The Superuser is the same as an administrator on Windows. But Linux has an additional level of security. The Superuser aka. administrator on a Linux computer can decide who can carry out tasks with Superuser privileges. This means, you might not be able to execute commands on a Linux computer with Superuser privileges, even if you know the root password if the administrator of the computer doesn’t want you to do so. However, if you are Linux admin you can permit certain users to carry out activities with Superuser privileges. Today I will discuss, how to do that.

So, without any further delay, let’s get started with how you can allow certain users to execute commands with administrator privileges.

Add user to sudoers on Ubuntu and Debian-based Linux

First I will discuss how you can allow certain users to carry out tasks with administrator privileges on Ubuntu and Debian-based distributions of Linux.

Let me consider you have a Linux user with the name ‘test’ who don’t have any Superuser privileges.

To offer Superuser privileges to the user ‘test’ you have to log in to the root user or a Linux user account that already has Superuser privileges.

In general, all the users who are within the user group ‘root’ will already have Superuser privileges.

After you log into the account with Superuser privileges, type in the following command and hit the enter key.

sudo usermod -aG “usergroup” “username”

The command for my case will be the following. 

sudo usermod -aG sudo test

command to Add user to sudoers on Ubuntu

You will not get any message if the task is completed successfully, and the prompt will be available right after the execution of the command.

Now, you can log in as a user test and try executing some commands in the Linux terminal with Superuser privileges.

Here I am executing the ‘LS’ command with Superuser privileges and you can find it is working perfectly.

Add to sudoers group for Debian linux

Alternatively, you can even switch to the user test by typing in the following command

su – “username”

The command in my case will be as given below.

su – test

Now, you can try executing any commands with Superuser privileges by keeping the sudo keyword before the command. If the command is executed without any troubles, the user has been added to the sudoers list to carry out tasks and execute commands with Superuser privileges.

Add User to Sudoers group on CentOS and similar distributions

The process to add a user to the sudoers list to permit the user to execute commands and other tasks with administrator privileges are quite similar to that of Ubuntu.

Just login in as a Superuser, or as a user who has Superuser privileges already. Just like Ubuntu and Debian-based distributions, all the users in the ‘wheel’ user group will have Superuser privileges.

So if you want to add the user ‘test’ to the sudoers file the command will go as follows.

sudo usermod -aG wheel test

Add User to Sudoers group on CentOS

However, if you have logged in as a Superuser, you don’t have to keep the sudo keyword, and thus, the command will be as follows.

usermod -aG wheel test

Now you can try executing commands with Superuser privileges either by logging in as a user test or by switching to the user test on the command line terminal, with the following command.

su – test

As you can see, the LS command has been executed properly with Superuser privileges.

Add to sudoers file for Superuser privileges

In both cases, you will need to enter the administrator password a number of times for security purposes.

So, that was all about how you can add a user to the sudoers list to allow them to execute commands with Superuser privileges on A Linux based computer. Did you face any trouble or some questions in mind? Feel free to comment on the same below. 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.