Fix “username is not in the sudoers file. ….” Error in Ubuntu
Overview:
This guide shows how to fix the “username is not in the sudoers file. This incident will be reported” in Ubuntu Linux.
Page Contents
What is the sudoers file?
The sudoers file is a configuration file in Linux and other Unix-like operating systems that defines which users or groups have administrative capabilities, allowing them to execute commands with root or superuser access using the sudo command. It is usually stored at "/etc/sudoers
“.
If a user is not in the sudeors file and tries to run a command using sudo, the user will encounter this error:
“username is not in the sudoers file. This incident will be reported”
How Can I Fix the Above Error?
In this section, we will cover the different ways to fix the “username is not in the sudoers file. This incident will be reported” error in Ubuntu.
Solution 1: Add user to sudo group
By default, in Ubuntu, all members of the sudo group are permitted to run any command as defined in the sudoers file. So, adding a user to the sudo group allows them to invoke the sudo command.
Switch to the root user account by running the following su command. Enter your account password to authenticate and proceed.
$su OR $su - #directly land in the root home directory
Then run the following usermod command to add the user, for example, fossman to the sudo group:
#usermod -aG sudo fossman
Then log out and log back in, the affected user should be grated with the message in the screenshot showing that they can from now on run commands with sudo. You can also check the affected user’s groups using the groups
command. The sudo group should be listed in the list of groups.
$groups
Next, test if the user can now invoke sudo like this:
$sudo apt update
Solution 2: Add user to sudoers file
Like before, switch to the root user account using the su command. Also enter your account password to authenticate and proceed.
$su
Next, open the sudoers file using the visudo
command like this:
$visudo
Then add the following configuration at the end of the file.
fossman ALL=(ALL:ALL) ALL
Save the file by pressing Ctrl + O
, then press Enter
to save changes and Ctrl + X
to exit.
For more information, read the sudo_root man page like this:
$man sudo_root
Conclusion
In this guide, we have shown how to fix the “username is not in the sudoers file. This incident will be reported” in Ubuntu Linux. Share your comments or questions via the feedback form below.