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.
|Adding User to Sudo Group
|Root or Sudo Privileges
|Ubuntu, Manjaro, Fedora, etc.
|useradd, passwd, usermod, gpasswd
Two Ways to Add a User to a Sudo Group
- By using the usermod command (for Ubuntu, Debian, Manjaro, etc).
- 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]
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:
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
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
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
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.