This post shows students and new users steps to add a user to the sudoers file on Ubuntu Linux. The sudoers file is a file used on Linux systems to give administrative rights to system users.
The root or administrator account in Linux gives you a lot of power. The root user can change the runlevel of a system, change and remove any file, remove software, add and remove accounts and a lot more.
You can practically do anything in Linux with the root account.
Using the root account to manage your system can be dangerous. In most cases, you won’t get a chance to confirm that you want to execute certain tasks before executing, even if the commands would damage the system.
That’s why a sudo process was added to prevent running Linux as root. With sudo, there are some checks and safeguards to prevent users running commands that will cause serious damage without first confirming the actions.
To understand the sudo and su processes and how they work, please read the post below:
What is sudo or su command on Ubuntu Linux
Now that you understand sudo and su and their differences, continue below to learn how to add a user to the sudoers file to allow the user run commands with the sudo process.
How to add a user to sudoers file to run sudo command
To allow regular user run commands with administrative privileges on Ubuntu Linux, you need to make them use the sudo process. You can achieve this in two ways:
One way is to add the user to the sudoers group which is already specified in the sudoers file with all the necessary administrative permissions. The other is to manually append the user to the sudoers file that define which elevated privileges to assign to the user.
Below we’ll show you how to do that.
How to create a user in Ubuntu Linux
If you don’t already know how to create a user account on Ubuntu Linux, then the post below should help you do that.
Read the post below to learn how to create a user on Ubuntu Linux
How to create a user on Ubuntu Linux
Now that you know how to create and remove users on Ubuntu Linux, continue below to learn how to add a user to the sudoers file.
To add a user to the sudoers, use the usermod command to add the user to the sudoers group.
sudo usermod -aG sudo username
Replace username with the user account name on Ubuntu.
For example, to add a user named octopus to the sudoers group, run the commands below:
sudo usermod -aG sudo octopus
Next, you can verify that octopus belongs to the sudo group by running the commands below.
groups octopus
One of the groups listed will be the sudo group. Now octopus can use the sudo command process to run administrative tasks.
Another way to add allow octopus to run with root or sudo privileges is to append the account to the sudoers file. As mentioned above, the sudoers file defines the users and groups privileges.
The sudoers file at /etc/sudoers can be invoked using the command below.
sudo visudo
Now, to allow octopus to run all with root privileges, append the line below into the file and save.
octopus ALL=(ALL:ALL) ALL
Save the close the file and octopus should run commands as administrator.
That should do it!
Conclusion:
This post showed you how to add a user to the sudoers file on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.