HomeLinuxHow to Fix “username is not in the sudoers file” Error in Ubuntu

How to Fix “username is not in the sudoers file” Error in Ubuntu

If you’ve encountered an error message: “Username is not in the sudoers file. This incident will be reported.” Similar to the image above, please do not be concerned; this guide will provide you with a step-by-step solution to address the issue. Follow along to regain access to administrative privileges on your Ubuntu system.

Step 1: Verify Your Username

Before making any changes, confirm the username you’re currently using. Open the terminal and type the following command:

whoami

This will display your username. Make a note of it!

Step 2: Switch to the Root User

There is a chance that your user account lacks sudo privileges therefore you must switch to the root user. This step requires prior setup if you don’t know the root password. Log in as the root user with command:

su

Enter the root password when prompted.

You’re now switched to the root user!

Step 3: Open the Sudoers File

The sudoers file controls, all users’ administrative privileges. Open it using the visudo command:

visudo

Editing this file by altering values can resolve the issue you face: username is not in the sudoers file.

Step 4: Add Your Username to the File

Scroll down to find the section that lists users and groups with sudo privileges in the opened file. Add a line for your username in the following format:

your_username ALL=(ALL:ALL) ALL

Replace your_username with the actual username you verified earlier.

Step 5: Save and Exit

To save your changes, press Ctrl + X, then press Y, and finally, hit Enter to confirm the changes.

Step 6: Exit the Root User Account

After saving the changes, exit the root account:

exit

Step 7: Verify the Fix

Now, try running a command that requires sudo privileges, such as updating the system or the command you faced issue earlier:

sudo apt update

If everything is configured correctly, the error should no longer appear now.

Why Use a VPS for Ubuntu?
Managing permissions and user privileges is easier when working in a reliable hosting environment. If you're using Ubuntu for a project, consider using a Veeble Unmetered Bandwidth Linux VPS. It offers a secure and customizable environment for running your applications seamlessly.

With these steps, you can successfully resolve the “Username is not in the sudoers file” error.

Scroll to Top