During your continued usage of an Ubuntu or Debian-based operating system environment, you probably encountered terminal-bound errors like “permission denied” or something like “user is not in the sudoers file”.
Such circumstances can be frustrating to a system user who is yet to fully grasp the rules that define the metrics of the Linux operating system. To kick off this article, we first need to understand the definition of Sudo and Sudoer from a Linux operating system perspective.
[ You might also like: How to Create a Sudo User in Ubuntu Linux ]
What are Sudo, Sudoer, and Sudo Privileges
Sudo (superuser do) is a Linux-bound command-line program that only allows permitted or OS-defined users to execute certain commands. These commands could be related to updating your Linux operating system or installing specific application software on the same operating system environment. You might also need to use the same commands to make certain programmable configurations on your Linux distribution system.
Therefore, the term “sudo privileges” refers to different levels of execution freedom granted to specific users on a Linux OS environment. A Linux user becomes a Sudoer when they start to benefit from these execution privileges.
Several approaches of adding system users to sudoers in Ubuntu exist. Let us explore them.
Adding Users to Sudoers Group in Ubuntu
Before we add a user to Sudoers in Ubuntu, this user needs to exist. You could use any user that already exists on your Ubuntu system but creating a new one makes this tutorial article a lot more interesting.
The first step is to switch the current system user to a root user using the following command:
$ sudo su
Create a new user on your Ubuntu system with the following command:
# adduser tutorials
You can give this user any name, on our case, we named the new user tutorials.
The next step is to verify the group name assigned to this new system user.
# id tutorials
The usermod command is effective in adding an ordinary Ubuntu Linux system user to the Sudoers group. To use this command, you have to adhere to the following syntax rule.
# usermod -aG sudo os_username
By substituting “os_username” from the above command syntax with our new user tutorials, we will be able to gift this new system user the needed Sudo privileges.
# usermod -aG sudo tutorials
If we try to verify the user group name of this tutorials user, we should see something different.
# id tutorials
As you can see, we now have Sudo as part of this new user group. To work with this new Sudo user, you can use the following command to switch to it.
# su tutorials
[ You might also like: How to Get Information About Other Linux Users ]
Adding Users to Sudoers File in Ubuntu
Your Ubuntu operating system’s Users + Group privileges are defined under the Sudoers file. The exact system location or path to this file is “/etc/sudoers”.
To invoke it, you will need the help of this simple command:
# visudo
The above command opens the Sudoers file on a nano text editor interface. You need to be the root user on your Ubuntu OS to execute the above command correctly.
To give tutorials the same user specifications as the root user, we must adhere to the following syntax rule:
os_username ALL=(ALL:ALL) ALL
The case of tutorials user will be implemented in the following manner:
tutorials ALL=(ALL:ALL) ALL
Use keyboard combinations Ctrl+O
, [Enter]
, and Ctrl+X
to save and close this Sudoer file.
Validating a Sudoer User in Ubuntu
To test if this tutorials user did indeed inherit any Sudo powers, we should run a system update through it.
$ sudo apt update
As you can see, the system update was a success. To counter this Sudoer user theory, let us create another system user without assigning any Sudo privileges and see if a system update will be possible.
# adduser tutor
Now switch to this user.
# su tutor
Try to run a system update through this tutor user.
$ sudo apt update
You will get an error:
tutor is not in the sudoers file. This incident will be reported.
As expected, the system update could not take place because the tutor user does not exist in the sudoer file.
Final Note
You now know two techniques of adding any system user to Sudoers under the Ubuntu operating system environment. The use of Sudo-prefixed commands by Sudoer users creates a safety net from executing crippling command sequences.
They also prevent unauthorized users from executing harmful commands. It is a different case when operating your OS as a root user because you do not get any prior warnings, leading to command executions that might completely crash your operating system.