Commands.page Logo

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

This guide explains how to resolve the ā€œuser is not in the sudoers fileā€ error in Ubuntu. This issue occurs when a standard user attempts to execute administrative commands without proper privileges. We will cover methods to grant sudo access using recovery mode or an existing administrative account, ensuring you can regain control of your system safely and efficiently.

Understanding the Error

The error message ā€œuser is not in the sudoers file. This incident will be reportedā€ appears when you try to use the sudo command with an account that lacks administrative permissions. Ubuntu restricts sudo access to specific users defined in the sudoers configuration file to protect the system from unauthorized changes. To fix this, you must add your user account to the sudo group.

Method 1: Using Another Administrative Account

If you have access to another user account on the system that already has sudo privileges, this is the easiest method.

  1. Log in to the account with sudo access.

  2. Open the terminal.

  3. Run the following command, replacing username with the name of the account that needs access:

    sudo usermod -aG sudo username
  4. Log out and log back into the restricted account.

  5. Test the access by running sudo ls /root.

Method 2: Using Recovery Mode

If you do not have any other account with sudo privileges, you must use the GRUB recovery menu to access the root shell.

  1. Restart your computer.

  2. Hold the Shift key or press Esc repeatedly during boot to display the GRUB menu.

  3. Select Advanced options for Ubuntu.

  4. Choose the kernel version ending with (recovery mode).

  5. In the Recovery Menu, select root (Drop to root shell prompt).

  6. The filesystem is mounted as read-only by default. Remount it as read-write by entering:

    mount -o remount,rw /
  7. Add your user to the sudo group using the following command:

    usermod -aG sudo username
  8. Type reboot to restart the system normally.

Verifying the Fix

Once you have logged back into your user account, verify that the permissions were applied correctly. Open a terminal and run:

sudo whoami

If the command returns root without displaying the sudoers error, the issue is resolved. You now have administrative privileges on your Ubuntu system.