Home » How-to » How to Fix User is Not in the Sudoers File in Ubuntu

How to Fix User is Not in the Sudoers File in Ubuntu

If you don't turn on an "Administrator" switch when creating a user in Ubuntu, and then log in and try to run sudo, you will get an error: "user is not in the sudoers file this insident will be reported."

In this short tutorial we will look at why this error occurs, and how to get around it and allow this user to act as a superuser.


Table of Contents

Why Does This Error Occur?

The sudo command allows users to execute programs as a superuser with full root privileges. Not all users can use the sudo command, but only those listed in the /etc/sudoers file. This error message is literally saying that your user is not in the sudoers file, which means that access to the utility will be denied and the incident will be reported to the administrator.

All failed attempts to use sudo, regardless of whether the password entered is incorrect or correct, are actually logged in the /var/log/auth.log, so you can see who tried to run any commands with sudo there:

tail /var/log/auth.log

Fixing the Error with Superuser Privileges

To fix the problem, all you need to do is allow the user to use sudo in the /etc/sudoers file. The entry allowing sudo use looks like this:

user_name ALL=(ALL:ALL) ALL

Or this:

%group ALL=(ALL:ALL) ALL

In Ubuntu, all users that are members of the admin group or the sudo group, and the root user can use sudo:

So you need to either add a new user to one of the groups, or add an entry for it in the /etc/sudoers file. But both of these can only be done with root privileges. So you need to have another user who can use sudo. If there is such a user, the problem becomes quite simple. But even if you don't, the problem is also quite solvable.

Let's start with the simpler option, in case you do have another user on the system who can use sudo. Authorize as that user and use the usermod command to add the new user to the admin group:

usermod -aG admin USERNAME

Or:

usermod -aG sudo USERNAME

You can also add a separate line for the user itself in the sudoers file:

/etc/sudoersUSERNAME ALL = (ALL) ALL

The next step is to save the changes to the file and re-authorize as the new user. If the /etc/sudoers file does not contain any lines that allow sudo users to use the utility, you can add this line:

vi /etc/sudoers%sudo ALL = (ALL) ALL

It may be enough to uncomment it by removing the hashtag character that precedes it. Then the error user is not in the sudoers file will disappear and you will be able to use sudo. You can read more about this in the article setting up sudo.

Correcting the Error With Grub

If there is no other user on your computer that you can access sudo as, you still have the option to use Grub and boot directly into Bash without using the initialization system. This is where you will have root access to the root file system. To do this, restart your computer and in the Grub menu press E.

This will open the editor for the selected menu item. In it, find the line that starts with linux /boot/vmlinuz and add init=/bin/bash to the end of it. It will look something like this:

Then you will boot into the /bin/bash shell with root privileges. By default, the root filesystem will be mounted read-only. To remount it for writing, run:

mount -o remount,rw /

After that, you will be able to run all of the above commands, such as adding the sudoers user by adding it to the sudo group:

usermod -aG sudo USERNAME

After running the command, you can reboot your computer using the reboot command with the -f option:

reboot -f

The next boot will be normal and you will be able to use sudo. If you want to avoid this problem in the future, enable the Administrator switch when creating a user in the GUI:

Conclusion

In this article, we covered what to do if you get the error user is not in the sudoers file, as well as how to add a user to sudoers ubuntu to avoid it. If you still have questions, feel free to ask in the comments section.

Rate the Article

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading...
Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required .

Leave a Comment