
When managing a server, you may sometimes want to allow users to run commands as root. In Ubuntu, sudo access allows users to run commands with the privileges of the root user. This is essential for performing system administration tasks, such as installing software, managing users, and configuring systems. In this guide, we’ll discuss how to add a user to Sudoers in Ubuntu 26.04.
Table of Contents
Prerequisites
- An Ubuntu 26.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
What is Sudo?
Sudo, short for SuperUser Do, is a command in Unix-based operating systems (Linux and macOS). This command allows users to run commands with administrator (root) privileges. This means that sudo grants users permission to perform tasks normally only accessible to the root user, such as installing software, changing system configurations, or managing users.
Sudo’s primary purpose is to improve system security. Instead of granting full access to the root account, users can be granted the ability to run certain commands with elevated privileges without logging in directly as root. Users authorized to use sudo are usually members of the sudo group or a similar group in Linux distributions.
What is root access?
In Linux, the term ‘root’ refers to the system administrator account. This account has complete control over the operating system, allowing it to modify any file, manage hardware, and bypass security measures. To modify system configuration files, install new applications, create user accounts, or perform any actions outside your home directory, you need root access.
The root account is the most powerful user account within the system. It has unrestricted access and can change anything — including files, settings, installed software, and system configurations — and it can also grant or revoke permissions for any user or process. Regular users (those without root access) do not have these extensive administrative privileges.
The root user is automatically a member of the root group; however, being in this group does not inherently grant the same superuser capabilities. Membership in the root group only confers privileges when:
- Specific files or directories are owned by the root group and have the appropriate group permissions set (such as read/write/execute for the group), or
- Additional mechanisms (most commonly sudo) have been configured to allow users in the root group (or other groups such as wheel, sudo, or admin) to elevate their privileges.
If you wish to grant a user root privileges, it is highly advisable to add them to the wheel or sudo group instead.
So, to add a user with sudo access on an Ubuntu machine, follow these steps.
Step 1. Log in to Your Server
First of all, we need to log in to our Ubuntu 26.04 VPS through SSH:
ssh root@IP_Address -p Port_number
Replace “root” with a user that has sudo privileges. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Ubuntu 26.04. You can verify it with this command:
# lsb_release -a
You should get this as the output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Resolute Raccoon
Release: 26.04
Codename: resolute
Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:
# apt update
That’s it, the system package information should be updated now.
Step 2. Add a New User
After logging in to the server as the root user, use the adduser command to add a new user to your system:
# adduser master
Make sure to replace master with the username you want to add. You will be prompted to create and verify a password for the user.
You will be asked to fill in some information about the new user you are adding. It’s okay to use the default information and leave it blank.
Changing the user information for master
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Step 3. Add User to the Sudo Group
Users authorized to use sudo are usually in the sudo group. To give a regular user full sudo access (i.e., the ability to run commands as root with sudo), add them to the sudo group using usermod.
# usermod -aG sudo master
Or, we can also use the gpasswd command.
# gpasswd --add master sudo
In addition to the commands above, you can use visudo to add users to the sudo group. Simply run the command below.
# visudo
Scroll down, then append this line below
master ALL=(ALL) NOPASSWD:ALL
Save the file, but before doing so, make sure to replace “master” with an existing system user on your Ubuntu 26.04. You can add the NOPASSWD: tag to allow specific commands (or all commands) to run via sudo without prompting for the user’s password. This is convenient for scripts, automation (e.g., cron jobs, Ansible playbooks), or headless servers, but it significantly reduces security. Anyone who gains access to that account can immediately execute privileged commands without authentication.
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:
master ALL=(ALL) NOPASSWD:/bin/ls,/bin/mkdir
Instead of editing the main /etc/sudoers file with visudo, a cleaner, more maintainable, and safer approach is to create a separate configuration file in the /etc/sudoers.d/ directory.
Ubuntu (and most modern Debian-based systems) automatically includes all files in this directory (as long as they follow the naming rules and have the correct permissions). This keeps your main /etc/sudoers file untouched and makes it easy to enable/disable or remove custom rules without risking syntax errors in the primary file.
# echo "master ALL=(ALL) NOPASSWD:ALL" | tee /etc/sudoers.d/master
To check your new sudoer permission, you can run the command below as the sudoer:
$ sudo -l
The command above will print this message to you:
Matching Defaults entries for master on ubuntu26:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User master may run the following commands on ubuntu24:
(ALL : ALL) ALL
Step 4. Test Sudo Access
The final step in adding a user with sudo on Ubuntu is to test whether the new access works. To do this, enter the su command to switch to the user account.
# su - master
Then, verify that you can use sudo by adding the command to run with privileges, for example:
$ sudo top
Another example: you can list the contents of the /root directory, which is normally only accessible to the root user:
$ sudo ls -la /root
The first time you use this session, you will be prompted for the password for that user account. Enter the password to continue.
Output:
[sudo] password for master:
This command will not prompt for the root password! Enter the password for the user with sudo access you just created.
If the user you added is in the correct group and you successfully entered the correct password, the command you issued will be successfully executed with root privileges.
In Conclusion
That’s it all! You have just learned how to add a user to the sudoer group in Ubuntu 26.04.
Of course, you don’t have to add a user to sudoers on Ubuntu 26.04 yourself if you use one of our managed hosting services, in which case you can simply ask our expert Linux admins to do it for you. Our expert administrators are available 24×7 and will take care of your request immediately. Simply log in to the client area, then submit a ticket, and we will add a user to sudo in no time.
If you liked this post on how to add a user to sudoers on Ubuntu 26.04, please share it with your friends or leave a comment below.