How to fix username is not in the sudoers file, this incident will be reported in Ubuntu. How to add user to sudoers file which is not in sudoers file.
Reason for the error “Username is not in the sudoers file
This error is reported in Ubuntu when:
- The permission on /etc/sudoers file is not set to 0440.
- User is not in sudo or admin group
- sudo Privileges error
1. Fixing Sudo Error Using /etc/sudoers
Open file
sudo nano /etc/sudoers
Then add the user below admin user like below syntax.
user_name ALL=(ALL) ALL
2. Fixing Sudo Error Using Grub
At first, you need to restart your PC or laptop. You need to press the Shift key immediately for a few seconds to get the Grub boot menu. If you are using Ubuntu then You need to select “Advanced options for Ubuntu” and press Enter. In the next window, select the kernel with the “recovery mode” option and press Enter to advance to the “Recovery menu”. In the next window, you need to select “root Drop to root shell prompt”, then hit Enter.
Next, press Enter for maintenance. Now run the following command in the shell mode to change filesystem mode to read/write from read only mode.
read/write by running the command below:
sudo mount -o rw,remount /
Now add user to sudo or admin group. Run the following command to add the user to the sudo or admin group.
sudo adduser user_name sudo
After adding the user to the suo or admin group, grant sudo privileges to users. Open the sudoers file using the command
sudo visudo
and add the following content in the sudoers file: # Defaults env_reset Defaults mail_badpass Defaults secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbi$ # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on “#include” directives: #includedir /etc/sudoers.d
Now set the correct permission on sudoers file using the following command to set the permission on sudoers file to 0440.
sudo chmod 0440 /etc/sudoers
Now, exit from the “Recovery menu” and reboot your Ubuntu System.