How to Add a user to Sudoers in Ubuntu Linux
There are different ways to obtain root privileges on Ubuntu, one of those methods is to run commands with root privileges using the sudo command. The sudo feature is used to provide administrative access to regular users, without actually sharing the root user's password.
In Ubuntu, there is a user group called sudo.
The user account you created During installation, is a member of sudo. If you want to add additional users to Sudoers, all you would need to do is add them to the sudo group using the usermod command.
sudo usermod -aG sudo user_name
Create Sudo User
Perform the following steps to create new sudo user in Ubuntu.
Create a normal account:
adduser testuser
Next, using the usermod command, add user to the sudoers (sudo group):
usermod -aG sudo testuser
let's check whether the new user now allow to run commands using sudo. First, log in to the newly created user account:
su testuser
Now, run the whoami command with sudo.
sudo whoami
You will be asked for the user account password (not the root password). The output returned by the whoami command should be root.
Once a user has been added to the sudoers, the user can execute any administrative command by preceding it with sudo.
The user would be asked to enter their own password instead of the root password.
The Ubuntu system determines if users are allowed to elevate to root permissions, based on the settings in the /etc/sudoers file.
If you want to edit /etc/sudoers file, use the visudo command which automatically checks your syntax when exiting. Do not edit this file directly using a text editor.