How to fix username not in sudoers file, this incident will be reported to Ubuntu. How to add a user to the sudoers file that is not in the sudoers file.
Cause of the error “Username is not in the sudoers file”
This error is reported on Ubuntu when:
- The permission for the /etc/sudoers file is not set to 0440.
- The user is not in the sudo or administrator group
- sudo privilege error
1. Fix Sudo error using /etc/sudoers
sudo nano /etc/sudoers
Then add a user under admin as shown below.
user_name ALL=(ALL) ALL
2. Fix Sudo error using Grub
First you need to restart your computer or laptop. You need to immediately press the Shift key and hold it for a few seconds to open the Grub boot menu. If you are using Ubuntu, you need to select “Ubuntu Advanced Options” and press Enter. In the next window, select the kernel with the “recovery mode” option and press Enter to go to the “Recovery Menu”. In the next window, you need to select “Root Shell Access” then press Enter.
Then press Enter to service. Now run the following command in shell mode to change the file system mode to read/write from read-only mode.
read/write by running the command below:
sudo mount -o rw,remount /
Now add the user to the sudo or administrator group. Run the following command to add the user to the sudo or administrator group.
sudo adduser user_name sudo
After adding a user to the suo or admin group, grant the users sudo rights. Open the sudoers file using the command
and add the following contents to 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 # Hint root privileges ALL=(ALL:ALL) ALL # Members of the admin group can gain root privileges %admin ALL=(ALL) ALL # Allow members of the sudo group to run any command %sudo ALL=(ALL:ALL) ALL # See sudoers( 5) for more information about “#include” directives: #includedir /etc/sudoers.d
Now set the correct permission for the sudoers file using the following command to set the permission for the sudoers file to 0440.
sudo chmod 0440 /etc/sudoers
Now exit the “recovery menu” and reboot your Ubuntu system.