How to Add User to Sudo Group

Linux TLDR
Last Updated:
Reading time: 2 minutes

If you are wondering what the sudo group is, it is the built-in group in Linux that holds the highest privilege after the root user.

Any users assigned to this group have the highest authority over the system, including the ability to install, remove, update packages, and modify system files.

If you are operating a server or system controlled by another sysadmin, they will give you a user account without sudo privileges.

However, if you have access to a sudo or root account, you can easily add your current user to the sudo group.

Tutorial Details

DescriptionAdding User to Sudo Group
Difficulty LevelModerate
Root or Sudo PrivilegesYes
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesuseradd, passwd, usermod, gpasswd
Internet RequiredNo

Two Ways to Add a User to a Sudo Group

  1. By using the usermod command (for Ubuntu, Debian, Manjaro, etc).
  2. By adding the user to the β€œ/etc/sudoers” file (for Red Hat, Fedora, AlmaLinux, etc).

We will begin by creating a new user account.

Creating a New User Account

Specify the username in the following command to create a new user account.

$ sudo useradd [USERNAME]

Updating the Password for the New User Account

Execute the following command with your username to update the password using the passwd command:

$ sudo passwd [USERNAME]
New password: 
Retype new password:

Adding a New User to a Sudo Group using the Usermod Command

Then use the β€œ-a” flag (will append the user) with the β€œ-G” flag (in group) using the usermod command.

$ sudo usermod -aG sudo [USERNAME]

Finally, restart your current session and place sudo in front of any command to execute it with sudo privileges as shown.

$ sudo apt update

Adding a New User to the Sudo Group by Modifying the /etc/sudoers File

Most of the time, you may not find the sudo group in RHEL-based distributions like Fedora or AlmaLinux.

If you try to follow the previous steps, you will end up with the following error:

Adding a user to the sudo group in RHEL-based distributions

In this case, you need to modify the β€œ/etc/sudoers” file with root or sudo privileges using your choice of text editor, as shown.

$ sudo nano /etc/sudoers

Now find the following comment in the file:

## Allow root to run any commands anywhere 

And then copy and paste the following line, replacing β€œlinuxtldr” with your actual username.

linuxtldr ALL=(ALL)   ALL

Output:

Adding users to the sudo group using the "/etc/sudoers" file

Save and close the file, restart your current session, and you are good to start using sudo in front of any command to get sudo privileges.

Checking the Current User Added in the Sudo Group

Use the username as an argument to the groups command to display the list of groups to which the specified user has been added.

$ groups linuxtldr

Output:

Checking whether the user is added to the sudo group

How to Remove a User from a Sudo Group

Execute the following command with the username to remove it from the sudo group.

$ sudo gpasswd --delete [USERNAME] sudo

Output:

Removing the user from the sudo group

If you have added the user to the sudo group using the β€œ/etc/sudoers” file, then remove the specified line and restart your session or system to reflect the changes.

That’s all for now; see you in the next article.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.