How to add users to Sudoers (and remove) on Ubuntu

Sudo command lets you perform any administrative task on Ubuntu. Here is how you can add the users to the sudoers. We will also show you how to remove users.

Have you ever needed to view/edit a file or even open a directory that needs some administrative privileges? As a normal user, you will not be able to view or open or edit files and directories with administrative privileges. However, in Linux, you can perform any task that requires administrative rights using the sudo command.

Using the sudo command, you will be allowed to perform any administrative task. However, to use the sudo command, the user should be added to a sudo group. Using the sudo command, you will be able to run any other command as a high privileged user.

Adding Users to Sudoers

In this tutorial, we are going to cover how to create a new user and assign this user to the sudo group. Even more, we will show you how to remove a user from the sudo group and revoke the given administrative privileges from this user. This tutorial was executed on Ubuntu 18.04LTS. Now, let’s discuss the following points:

  • Creating a new user
  • Adding a user to the sudo group
  • Removing a user from the sudo group

Creating a New User

In general, to create a new user in Linux, you should use the “adduser” command. So, the next command can be used to create a new user named “testuser”:

sudo adduser testuser

Add New Test User
Add New Test User

To use the “adduser” command, you need to be a root user, or you can use the sudo command to create a new user. Now, you will be asked to enter the new user password.

Enter Password For New User
Enter Password For New User

Moreover, you need to add some additional information, or just you can leave them blank.

Enter Additional Information
Enter Additional Information

The “testuser” is created successfully.

Adding a User To The Sudo Group

After creating the new user, you can now add this user to the sudo group using the next command:

sudo usermod -a -G sudo testuser

Add User To Sudo Group
Add User To Sudo Group

To make sure that the newly created user was added to the sudo group, you can use the following command:

sudo -l -U testuser

New User Added To Sudo Group
New User Added To Sudo Group

As you can notice, the output of the previous command will tell you the new user was added successfully to the sudo group. Now you can log in to the newly created user and start using the sudo command.

su - testuser

Login Using Newly Created User
Login Using Newly Created User

As you can notice, you will get a message telling that to run a command as an administrator, and you can use the sudo command. Now, let’s create a new directory using the sudo command.

sudo mkdir newdir

Create New Directory Using Sudo
Create New Directory Using Sudo

Congratulations, you are now in the sudo group and can execute any command as an administrator.

Removing a User From The Sudo Group

What if you need to delete the granted administrative privilege from a user? Do not worry this easy you will just need to logout from the new user as follows:

exit

Logout
Logout

Next, use the “deluser” command to remove the user from the sudo group as follows:

sudo deluser testuser sudo

Remove New User From Sudo Group
Remove New User From Sudo Group

As you can see in the previous screenshot, the new user was removed from the sudo group. Moreover, you can make sure that the user is not in the sudo group using the next command:

sudo -l -U testuser

Newly Created User Is not Allowed To Use Sudo Command
Newly Created User Is not Allowed To Use Sudo Command

As you can see in the above screenshot, the user is not allowed to run a sudo command because the user was removed from the sudo group. So, let’s login and try to use the sudo command.

su - testuser

Login To New User Again
Login To New User Again

sudo mkdir newdir

Use Sudo Command Again
Use Sudo Command Again

As you can notice, the logged-in user is not in the sudo group, and hence the user will not be able to use the sudo command anymore.

Finally, you have now learned a new command that can help you a lot using Linux. That’s it for now, and I hope you have enjoyed this quick tutorial.

Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,536FansLike
365FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to install CouchPotato on Ubuntu

Downloading movies and copying them over to your home server can get frustrating, especially if you are doing it daily! What if you have an option to download videos automatically, quickly, and above all with excellent quality. CouchPotato allows you to download movies easily once they are available and released automatically.

Top 20 Rsync Examples in Linux

The Rsync (remote sync) command is a Linux/Unix utility used to synchronize and copy files and directories either locally or remotely. Most Linux geeks use Rsync to mirror, backup or migrate data across folders, across disks and networks. One notable feature with the Rsync command is that it uses the "delta transfer algorithm."

Setting up NFS Server on Ubuntu Server

We have put together a detailed step-by-step tutorial that will guide you on how to install and set up NFS Server on Ubuntu so you too can start sharing data with other client systems. It is divided into sections, the first part discussing how to set up the host server and the second part showing you how to set up the client-side. For this tutorial, we will be using Ubuntu 20.04 LTS.

Crontab in Linux Explained With Examples

Crontab is the Linux equivalent of the Window's Task Scheduler. It can help you set up a task to run automatically at a regular...

The 10 Best Linux Server Distros For Home And Businesses

By the year 2020, it is estimated that there are close to 600 Linux distributions in the market. It includes both servers and Desktop versions; therefore, if you are looking for lightweight Linux distribution for your old PC or a reliable desktop version for employees in your organization, you may be overwhelmed with the number of choices for finding one for your use.

How to list the installed Packages on Ubuntu

It is only natural to start installing more and more software on your Ubuntu PC once you start using it. Similarly, it is also natural to lose track of the different packages that you have installed on your system. Eventually, you may be overwhelmed with the number of packages in your system and with the ones you hardly used.

MUST READ

Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

6 Essential Command-Line Utilities Every Linux User Should Know

Last week, we shared with you several "cool and fun" commands to get comfortable and confident with the Linux command-line. In our quest to further aid Linux users with mastery of the command line, or CLI, we present you with a variety of command-line utilities essential for all Linux users, regardless of proficiency level.

What’s New in Ubuntu 20.04 LTS “Focal Fossa”

Ubuntu 20.04 LTS is out now! This is the successor to Ubuntu 18.04, which was released in April 2018 and still has three years of official support left. Code-named Focal Fossa, the new edition has all the bells and whistles included in it, making it one of the best Ubuntu releases yet. Let's find out more.

Top 5 reasons to switch from Windows to Linux right now

Do you love Windows or Linux? Being on a Linux website, it's not hard to take a guess, but what are the strong reasons to switch to Linux? Linux is a 100% free OS. Is that reason alone enough? Let's find out! Never have there been more compelling reasons to make the switch. Here are just five great reasons for users to create that magical move from the wayward world of Windows to the lauded land of Linux.

Manjaro ‘Gellivara’ XFCE Edition (17.0.5) in 10 Screenshots

Want to take a quick virtual tour Manjaro XFCE edition instead of downloading GBs worth of ISO image and then making a Live USB of it? We will make it easy for you. Here are a series of screenshots of the important aspects of Manjaro Linux in XFCE edition. This is a light-weight edition, and aims to be fast and low on system resources. You will be amazed on how it is still visually appealing and user friendly.