Fix 'Username not in sudoers file' error in Linux | Quick solutions
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:
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:
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.
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.