This post shows students and new users steps to add a user to the sudoers file on Ubuntu Linux. The sudoers file is 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 run level 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 to confirm that you want to execute certain tasks before executing, even if the commands would damage the system.
A sudo process was added to prevent running Linux as root. With sudo, some checks and safeguards prevent users from 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 the 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 to run commands with the sudo process.
How to add a user to the sudoers file to run the sudo command
To allow regular users to run commands with administrative privileges on Ubuntu Linux, you must make them use the sudo process. You can achieve this in two ways:
One way is to add the user to the sudoers group, 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 defines 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 know how to create a user account on Ubuntu Linux, the post below should help.
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 the 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, by running the commands below, you can verify that the octopus belongs to the sudo group.
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 and allow the octopus to run with root or sudo privileges is to append the account to the sudoers file. As mentioned above, the sudoers file defines user and group privileges.
The sudoers file at /etc/sudoers can be invoked using the command below.
sudo visudo
To allow the 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:
- Adding a user to the sudoers file is essential for granting administrative privileges in Ubuntu Linux.
- Utilizing the
usermod
command is a straightforward method to add a user to the sudo group. - The
visudo
command provides a safe way to edit the sudoers file directly and set specific permissions. - Always verify user group memberships to ensure correct configurations.
- By using sudo, users can perform administrative tasks while minimizing the risks associated with operating as the root user.
Leave a Reply