Fix Error User Not in Sudoer File on Ubuntu: 1 Best Solution
In this guide, we want to teach you How To Fix Error User Not in Sudoer File on Ubuntu. When you want to run Linux Commands with sudo privileges on your Ubuntu server, you may get this error that said User Not in Sudoer File. This will happen when the sudo user is not in the sudo group on your Ubuntu server. You can follow the steps below to fix it.
To complete this guide, you must have access to your server as a root user. Then, follow the steps below to Fix Error User Not in Sudoer File on Ubuntu.

Step 1 – Create a non-root User on Ubuntu
First, we will create a non-root user to show you how it will happen. To do this, run the command below:
adduser orcacore
Enter a password for your user:
Output
Adding user `orcacore' ...
Adding new group `orcacore' (1000) ...
Adding new user `orcacore' (1000) with group `orcacore' ...
Creating home directory `/home/orcacore' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for orcacore
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] y
Now switch to your user account with the following command:
su - orcacore
Step 2 – Fix User Not in Sudoers File Error on Ubuntu
At this point, when you want to try to run the sudo commands with your user, you will get the following error:
sudo -i
Output
[sudo] password for orcacore:
orcacore is not in the sudoers file. This incident will be reported.
To Fix Error User Not in Sudoer File on Ubuntu, you must add your user to the correct group. In Ubuntu servers, you just add the user to the sudo group.
To do this, switch back to your root account with the following command:
su -
Enter your root password and press enter.
Then, use the following command to add your user in the sudoers file:
usermod -aG sudo orcacore
To apply the changes, reboot your Ubuntu server with the command below:
systemctl reboot
Step 3 – Verify that the User is in the Sudoers File
When you log back to your server, switch to your user account again:
su - orcacore
You will see the following output:
Output
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
This means that you have added your user to the sudoers file correctly.
Conclusion
At this point, you have learned How To Fix Error User Not in Sudoer File on Ubuntu. As you saw, it will happen when your user is not in the correct sudo group.
Hope you enjoy it. You may be interested in these articles:
How To Change SSH Port on Debian
Check HTTPS Port 443 is Open on Linux
How To Manually Install Driver Module in Linux
FAQs
What does the “User is not in the sudoers file” error mean?
It means that the current user has no access to admin privileges for running commands with sudo.
Why do I need sudo permissions on Ubuntu?
The sudo allows you to run commands with root privileges which is necessary for installing, managing, and performing admin tasks.
How do I verify if my user is in the sudo group?
You can use the groups username
to check the membership.
Alternative Solutions to "User Not in Sudoers File"
While the method described above, adding the user to the sudo
group, is the most common and recommended way to grant sudo privileges, there are alternative methods to Fix Error User Not in Sudoer File on Ubuntu. These methods are less commonly used but can be helpful in specific situations.
Alternative Solution 1: Modifying the /etc/sudoers
File Directly
This method involves directly editing the /etc/sudoers
file, which controls sudo access. However, it’s crucial to use the visudo
command to edit this file, as it provides syntax checking and prevents you from accidentally corrupting the file and locking yourself out of sudo access.
Explanation:
The /etc/sudoers
file contains a list of users and groups and the commands they are allowed to run with sudo
. By adding a line for the user, you can grant them specific or unrestricted sudo access.
Steps:
-
Become the root user:
su -
-
Open the
/etc/sudoers
file usingvisudo
:visudo
- This will open the file in a text editor (usually
vi
ornano
, depending on your system’s configuration).
- This will open the file in a text editor (usually
-
Add a line for your user:
-
To grant the user full sudo access (equivalent to being in the
sudo
group), add the following line, replacingorcacore
with the actual username:orcacore ALL=(ALL:ALL) ALL
-
This line means: "The user
orcacore
can run any command (ALL
) on any host (ALL
) as any user (ALL
) and any group (ALL
)". -
To grant the user access to specific commands only, you can replace the final
ALL
with a comma-separated list of commands (including their full paths). For example:orcacore ALL=(ALL:ALL) /usr/bin/apt-get update, /usr/bin/apt-get upgrade
-
-
Save the file and exit the editor:
- In
vi
, pressEsc
key, type:wq
, and pressEnter
. - In
nano
, pressCtrl+X
, thenY
to confirm saving, and pressEnter
.
- In
-
Test the sudo access:
- Switch back to the user account:
su - orcacore
- Try running a command with
sudo
:sudo apt-get update
- Switch back to the user account:
Caution:
- Incorrectly editing the
/etc/sudoers
file can prevent you from usingsudo
. Always usevisudo
to edit the file. - Be careful when granting full sudo access. It’s generally recommended to grant access only to the commands that the user needs.
- Syntax errors in the
/etc/sudoers
file can be difficult to troubleshoot.
Alternative Solution 2: Creating a Custom Sudoers File
Instead of directly modifying the /etc/sudoers
file, you can create a separate file within the /etc/sudoers.d/
directory. This directory is specifically designed for including additional sudoers configurations.
Explanation:
The /etc/sudoers.d/
directory allows for a modular approach to managing sudo privileges. Each file within this directory is read by sudo
, allowing you to organize and manage permissions in a more structured way.
Steps:
-
Become the root user:
su -
-
Create a new file in
/etc/sudoers.d/
:nano /etc/sudoers.d/orcacore
- Replace
orcacore
with a descriptive filename (e.g., the username).
- Replace
-
Add the sudo privileges for the user to the new file:
-
To grant the user full sudo access:
orcacore ALL=(ALL:ALL) ALL
-
To grant the user access to specific commands only:
orcacore ALL=(ALL:ALL) /usr/bin/apt-get update, /usr/bin/apt-get upgrade
-
-
Save the file and exit the editor:
- In
nano
, pressCtrl+X
, thenY
to confirm saving, and pressEnter
.
- In
-
Set appropriate permissions for the file:
chmod 0440 /etc/sudoers.d/orcacore chown root:root /etc/sudoers.d/orcacore
- These commands ensure that only the root user can write to the file and that the file is owned by the root user and group.
-
Test the sudo access:
- Switch back to the user account:
su - orcacore
- Try running a command with
sudo
:sudo apt-get update
- Switch back to the user account:
Advantages:
- Organization: Keeps your sudo configurations organized and separated from the main
/etc/sudoers
file. - Easier Management: Makes it easier to manage individual user or group permissions.
- Reduced Risk: Reduces the risk of accidentally corrupting the main
/etc/sudoers
file.
Caution:
- Ensure the files in
/etc/sudoers.d/
have the correct permissions (0440) and ownership (root:root). - As with directly editing
/etc/sudoers
, be careful when granting full sudo access and consider granting access only to necessary commands.
These alternative solutions provide different approaches to granting sudo privileges. Choosing the right method depends on your specific needs and the level of control you require. However, adding the user to the sudo
group remains the simplest and most common approach for most use cases when you encounter Fix Error User Not in Sudoer File on Ubuntu. Always prioritize security and grant only the necessary privileges to avoid potential security risks.