Regular users can be added to the sudoers list on Linux systems to gain administrative access. This enables them to run system commands with root access without having to share the root password. In this article, I’ll show you How to Add Users to Sudoers in Linux step by step procedures.
Table of Contents
Prerequisites
- A system running an Ubuntu supported version
- Access to a
root
user account or another account withsudo
permissions - Terminal window/command line access (Ctrl-Alt-T)
What is Sudoers File
The sudoers
file is critical in Unix-based operating systems such as Ubuntu because it determines whether users or groups have authorization to use the sudo command to conduct privileged operations. It is placed at '/etc/sudoers'
and consists of a set of rules that govern the commands that users can perform as well as their level of access.
In Linux, people can be granted access to the sudoers
file via manual editing or by using the usermod
command, with both methods serving the goal adequately. The latter approach is frequently regarded as cleaner and more recommended.
Steps to Create a New sudo user in Linux
Follow these procedures to create a new user named “bob” and add them to the sudoers list:
Step1 : Log in as root or a user with sudo
privileges.
Step2 : Launch a terminal.
Step3 : To create the new user, execute the following command:
sudo adduser bob
This command will question you for additional information about the new user. You can enter the required data, such as a password, complete name, phone number, and other optional entries.
Enter to skip any fields you want to leave empty.
cloudbooklet@cloudbooklet:~$ sudo adduser bob
Adding user ‘bob' ...
Adding new group ‘bob' (1002)
Adding new user ‘bob' (1001) with group 'bob' ...
Creating home directory '/home/bob’ ...
Copying files from '/etc/skel' ...
Enter new UNIX password
Retype new UNIX password:
passwd: password updated successfully
changing the user information for bob
Enter the new value, or press ENTER for the default
Full Name []: New User
Room Number []
work Phone [
Home Phone [
other []:
Is the information correct? [¥/n] y
cloudbooklet@cloudbooklet:~$
Once you have completed these steps, the new user account will be created, along with a corresponding group and home directory for that user. The user can now log in to the system using their username and password.
Add User into Sudo Group
Using the usermod
command, you can add an existing user, such as “bob,” to the sudo
group.
To add “bob” to the sudo
group, use the following command:
sudo usermod -aG sudo bob
The -a
flag add users to the specified group, and the -G
flag specifies the group, which in this case is “sudo.”
After running the script, use the groups command to see if the user “bob” was successfully added to the sudo group.
Here’s how to use it:
groups bob
output
cloudbooklet@cloudbooklet:~$ sudo usermod -aG sudo bob
[sudo] password for cloudbooklet:
cloudbooklet@cloudbooklet:~$
cloudbooklet@cloudbooklet:~S groups bob
bob : bob sudo
cloudbooklet@cloudbooklet:
Alternative Command
To add the user “bob
” directly to the sudoers
file, use the adduser
command as follows:
- Log in as
root
or a user withsudo
privileges. - Launch a terminal.
- To add the user “bob” and provide them
sudo
rights, run the following command:
sudo adduser bob sudo
- During the user creation process, this command adds the user “bob” to the sudo group.
- When prompted, enter a password for the new user and any other information requested.
After you finish these steps, the user “bob” will gain sudo capabilities and will be able to run commands with elevated permissions using the sudo command. - When using sudo, they must input their own password to authenticate themselves.
- Using the adduser command with the sudo parameter streamlines the procedure by add user to the sudo group and granting them administrative privileges.
- Replace “bob” with the username you want to add to the sudoers list.
Also read: For a more comprehensive overview of Add and Remove Users refer to our guide How to Add and Remove Users in Linux
Benefits of Adding Users to the sudoers
File
Benefit | Description |
---|---|
Increased security | Users with sudo access have the ability to run commands with root privileges, which can be helpful for tasks such as installing software, managing system services, and troubleshooting problems. It is crucial to note, however, that providing users sudo access can increase the risk of security breaches. As a result, it is critical to carefully assess which users should be added to sudoers and to withdraw their access if it is no longer required. |
Improved system management | Administration Add users to sudoers can help you manage your system more easily. If you have a big number of users, for example, you can form a group for all sudo users and then administer the group as a whole. This can help you save time and effort. |
Increased flexibility | Add users to sudoers can provide you more control over how your system is managed. You can, for example, grant varying levels of sudo access to different users. This can be beneficial if you want to grant some users more privileges than others. |
Conclusion
To summarize, add users to the sudoers list in Linux is critical for securely providing administrative access. Administrators of systems can assure controlled access to important commands and a robust security architecture by following the proper instructions and configurations. Please feel free to share your thoughts and feedback in the comment section below.