How to Fix “Username is Not in the Sudoers File”?
In the Linux Distribution, there are two methods to solve this error. So we will look at each method in step by step approach.
- Method 1: Changing Configuration File (/etc/sudoers.d)
- Method 2: Adding User in Sudo Group
Let’s explore each of the resolving methods in detail with proper steps and commands.
Method 1: Changing Configuration File (/etc/sudoers.d)
The main configuration file of sudo for user entry is present in /etc/sudoers.d directory. So first if you have the root password kindly login as root for making a changes or entry in the configuration file.
Step 1: Login as Root User
sudo -s
- -s: To start a shell with root privileges.
Step 2: Open the Configuration File
nano /etc/sudoers.d/kali-grant-root
- nano: nano is the common text editor used by many Linux distributions.
- /etc/sudoers.d/kali-grant-root: Since, for this demonstration, a Debian-based(kali) is used the main configuration for user grant resides in this location.
Step 3: Making Entry in Configuration File
demo ALL=(ALL:ALL) ALL
- demo: You need to mention the username. For this demonstration username “demo” is used.
- ALL=(ALL:ALL) ALL : It will give all administrative permission to this particular user.
Step 4: Re-evaluation of permissions
sudo apt update
To verify whether the error is fixed or not, update the repository with the help of the sudo command by using the “demo” user.
Method 2: Adding User in Sudo Group
In this scenario, you will see how we can add the user to the sudoer group with the help of the “usermod” command.
Step 1: Adding user into sudoers Group
sudo usermod -aG sudo demo
- usermod: A “usermod” is a command utility to manage the permissions and do the configuration for each particular user.
- -a: It means append the group or list of group
- -G: It means to specify the groupname/username of which the user is also a member.
Step 2: Rechecking the Permissions (Verification)
After adding the user into the sudo group, restart the system to make it permanently changes. Then try to use the administrative task.
sudo passwd demo
- passwd: It is a command utility tool used to change the user account password.
How to Fix “Username is Not in the Sudoers File”
Encountering the “Username is Not in the Sudoers File” error in a Linux environment can be a frustrating roadblock for users attempting to execute privileged commands. The sudoers file is a crucial configuration that governs user permissions for administrative tasks. When a user is not included in this file, they are denied access to perform actions requiring elevated privileges. This article will guide you through the steps to resolve this issue, providing a comprehensive overview of how to add a user to the sudoers file and regain the necessary permissions for seamless system management.
Contact Us