Fix 'Username not in sudoers file' error in Linux | Quick solutions

├Źndice
  1. Introduction
  2. Method 1: Add User to sudo Group
  3. Method 2: Edit sudoers File
  4. Method 3: Use su Command
  5. Conclusion

Introduction

If you're an avid Linux user, you may have come across the "Username not in sudoers file" error. This error message is displayed when a user tries to execute a command with sudo privileges, but their username is not listed in the sudoers file. In this article, we'll go over some quick solutions to fix this error.

Method 1: Add User to sudo Group

The easiest way to fix this error is by adding the user to the sudo group. To do this, log in as the root user and enter the following command:

usermod -aG sudo username

Replace "username" with the name of the user you want to add to the sudo group. Once you've entered the command, the user will be able to use sudo privileges without encountering the error.

Method 2: Edit sudoers File

If you don't want to add the user to the sudo group, you can edit the sudoers file directly. To do this, log in as the root user and enter the following command to open the sudoers file:

visudo

Once the file is open, scroll down to the section that starts with "# User privilege specification". Underneath that section, add the following line:

username ALL=(ALL) ALL

Again, replace "username" with the name of the user you want to grant sudo privileges to. Save the file and exit the editor. The user will now be able to use sudo privileges without encountering the error.

Method 3: Use su Command

If neither of the above methods work, you can use the su command to switch to the root user and execute commands as root. To do this, enter the following command:

su

You will be prompted to enter the root password. Once you've entered the password, you can execute commands as the root user without encountering the error.

Conclusion

The "Username not in sudoers file" error can be frustrating, but there are several quick solutions to fix it. By adding the user to the sudo group, editing the sudoers file, or using the su command, you can grant the user sudo privileges and avoid encountering this error in the future.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information