Linux: 'Username' is not in the sudoers file. This incident will be reported [closed]

Solution 1:

Open file

sudo nano /etc/sudoers

Then add the user below admin user like below syntax.

user_name ALL=(ALL)  ALL

Solution 2:

Both the above answers are correct as far as they go but it is easier to add your user to the sudo group in debian based systems (Ubuntu, kbuntu, debian, etc) and the wheel group under RedHat based systems (RedHat, Fedora, CentOS, etc)

usermod -a -G sudo user
or
usermod -a -G wheel user 

Solution 3:

This is a very common error for the beginners. The error occurs because we are trying to access/update something with super privileges from the user instead of root -user.

Hence, to solve this,we need to make changes in the sudoers file where the root user has been given the privileges. So, switch to root user,run the following command

sudo su 
# vi /etc/sudoers

The editor would open the file, now scroll down to the bottom where you will see a line

#User privilege specification

root     ALL=(ALL:ALL) ALL

username ALL=(ALL:ALL) ALL

As you can see, I have just added my username with all permissions.

Save the file, and exit. Switch back to the user and start using sudo commands with ease.

Solution 4:

Got a slightly different syntax to Rodney's from my host

usermod -aG wheel username

Their explanation was

The user will need to be added to the wheel group.

Use the usermod command to add the user to the wheel group.

You may need to log off and log back in after doing this

Solution 5:

At the top of the aforementioned /etc/sudoers file there's an info:

"## This file MUST be edited with the 'visudo' command as root."

In order of doing as we're told, use:

$ su
> Enter root password: *******
$ visudo -f /etc/sudoers

Find the following section of /etc/sudoers file and add your users privileges:

# User privilege specification
root    ALL=(ALL:ALL) ALL
user_name ALL=(ALL) ALL

Save the file (press esc and type :x if vim is your default text editor, for nano press ctrl+o, enter and then ctrl+x).

Type exit to turn off the root shell, and enjoy the power of sudo with your username