
Ubuntu derives from the South African philosophy of “humanity to others”. With the hope that the Ubuntu operating system would connect people across the globe. Today, Ubuntu is a popular operating system due to its ease of installation and use. This is true for both desktops and servers. In a Linux environment, there is a default user named root. This has the highest level of authority on the system. Therefore, when you install Ubuntu desktop, your access is restricted since you are not utilizing root as the default user. The word root also has several additional meanings when combined with other terms. This is one of the sources of confusion for people new to using GNU/Linux-based operating systems. In this article, we will show you how to add user to sudoers in Ubuntu 24.04.
Table of Contents
Prerequisites
- An Ubuntu 24.04 VPS
- SSH root access or a regular system user with sudo privileges
Conventions
# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user
Root Access
Root privileges or root privileges are the powers held by the root user/account on a system. The “root” user account on a Linux system holds full administrative control over all aspects of the system. To edit system configuration files, install new software, add user accounts, or undertake any tasks beyond your home directory, you need root access.
The root account is the most privileged account and has the highest level of power, including the ability to modify the system as desired and to grant or revoke access permissions. For regular users, these abilities are not available.
The root user is a member of the root group, but the root group does not grant any inherent powers or privileges like the root user. This means that the permissions you get from group root are either because of group permissions on files in the root group or because of things like sudo, which may be configured to grant additional permissions.
If you want to add a user to have root privileges, it is highly recommended to add the user to the wheel or sudo group instead.
Step 1. Update the System
Let’s log in to your Ubuntu 24.04 VPS through SSH as a root user or as a regular user with sudo privileges.
ssh root@IP_Address -p Port_number
If you cannot log in as root, remember to substitute “root” with a user that has sudo privileges. Additionally, change “IP_Address” and “Port_Number” to match your server’s IP address and SSH port.
You can check whether you have the correct Ubuntu version installed on your server with the following command:
$ lsb_release -a
You should get this output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.3 LTS
Release: 24.04
Codename: noble
Step 2. Add a System User
Let’s create a new system user called ‘admins’, run this command:
# adduser admins
You will be prompted to create a password.
info: Adding user `admins' ...
info: Selecting UID/GID from range 1000 to 59999 ...
info: Adding new group `admins' (1001) ...
info: Adding new user `admins' (1001) with group `admins (1001)' ...
info: Creating home directory `/home/admins' ...
info: Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for admins
Enter the new value, or press ENTER for the default
Full Name []: Administrator
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
info: Adding new user `admins' to supplemental / extra groups `users' ...
info: Adding user `admins' to group `users' ...
Make sure to use a strong password when prompted.
Step 3. Add User to Sudoer
On Ubuntu machines, the “sudo” group grants sudo privileges. So, to add a user to the sudo group, let’s run this command:
# usermod -aG sudo admins
or
# gpasswd --add admins sudo
Make sure to replace ‘admins’ with the actual username on your Ubuntu system. Additionally, when running the usermod command, make sure to use -a as the default option. If you don’t add the -a option in the usermod command above, that user is removed from all groups it was already a member of and will be only a member of the sudo group.
Please bear in mind that granting a user sudo privileges effectively grants them root access. This level of access should be reserved for trusted users who need higher permissions to run administrative tasks, as they will get full access to your server.
In addition to using one of the commands above, you can also use visudo to add users to the sudo group. Simply run the command below.
# visudo
Scroll down, then append this line below
admins ALL=(ALL) NOPASSWD:ALL
Save the file, but before doing so, make sure to replace “admins” with an existing system user on your Ubuntu 24.04. The NOPASSWD tag can be used to allow certain commands to be executed without prompting for the user’s password, which can be beneficial for automation like cronjobs, but may increase security vulnerabilities.
Another example is allowing a user to run only certain commands with sudo. For example, to allow only the mkdir and rmdir commands, you would use:
admins ALL=(ALL) NOPASSWD:/bin/ls,/bin/mkdir
Instead of running the visudo command above, you can also create a new file under the /etc/sudoers.d directory. Add the same rules that you added to the sudoers file:
# echo "admins ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/admins
To check your new sudoer permission, you can run the command below as the sudoer:
sudo -l
The command above will print this message:
Matching Defaults entries for master on ubuntu24:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User admins may run the following commands on ubuntu24:
(ALL : ALL) ALL
Bringing it all together!
That’s it all! You have learned how to add a user to the sudoer group to give them root privileges.
Of course, you don’t have to add a user to sudoers in Ubuntu 24.04 if you use one of our Linux VPS Hosting services, in which case you can simply submit a ticket to ask our expert Linux administrators to add a user to sudoers in Ubuntu 24.04 for you for free. Our system administrators are available 24×7 and will address your request immediately.
If you liked this post about how to add a user to sudoers in Ubuntu 24.04, please share it with your friends on the social networks using the share buttons below, or simply leave a comment in the comments section. Thanks.