Fix Error User Not in Sudoer File on Ubuntu

In this guide, we want to teach you to How To Fix the 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.

How To Fix Error User Not in Sudoer File on Ubuntu?

To complete this guide, you must have access to your server as a root user.

Then, follow the steps below to fix this error.

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 this error, 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 logged 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 the 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

1 COMMENT
  1. I really appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thx again

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular