Linux - Add User to Sudoers List With Examples

Most of the system commands can be run as a root user or a user with sudo privileges. It’s not a good idea to always login as a root user. The secure way is to disable root login after creating a new user and providing him sudo privileges.

In this tutorial, we will learn how to add a user to sudoers list in Linux. The commands are generic to Linux and they will work on every distributions, such as Ubuntu, CentOS, Debian, etc.

Steps to Add a User to sudoers list in Linux

1. Create a User

Let’s first create a user for our tutorial. This is an optional step. If you already have a user to add to the sudoers list, then you can skip this step.

We will use adduser command to create a user. You should be logged in as root or a user with sudo privileges to run these commands. If you are a sudo user, then add “sudo” before all the commands.

The most important point is to remember the password for the new user.

Let’s run the groups journaldev command to check the user group details.

Linux Create New User

2. Add user to the sudo group

We can add the user to the sudo group using the following command.

Let’s again check the user groups to confirm that he has been added to the sudoers list.

Linux Add User To Sudo Group

3. Validate the Sudo Access of the user

Let’s quickly validate that the user is part of the sudoers list by running some commands with “sudo” prefix.

First of all, use the su command to change the user.

Let’s run some commands as the normal user and then as the superuser using sudo prefix.

Linux User Sudoers Validation

That’s it. Our user is part of the sudoers list. We can run any command as a superuser now.

By admin

Leave a Reply