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

LinuxSudoers

Linux Problem Overview


After logging into ssh, I got this message:

>'Username' is not in the sudoers file. This incident will be reported.

How can I resolve this? I'm connecting ssh to my virtual private server.

Linux Solutions


Solution 1 - Linux

Open file

sudo nano /etc/sudoers

Then add the user below admin user like below syntax.

user_name ALL=(ALL)  ALL

Solution 2 - Linux

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 - Linux

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 - Linux

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 - Linux

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

Solution 6 - Linux

You should use visudo to edit /etc/sudoers file.

Just run sudo visudo -f /etc/sudoers

and add your username with correct syntax and access rights. You can find more in man sudoers

Solution 7 - Linux

  1. Entered Root using command $ su root. Input Root Password

  2. Install sudo: $ apt-get install sudo -y

  3. Add your < username> $ adduser <username> sudo

  4. $ exit

  5. Then sign up and sign in the < username> session

  6. Finally, check with: < username>@< hostname>:~$ sudo apt-get update

Solution 8 - Linux

try this video, it works for me.

  1. ssh root@localhost
  2. sudo vi /etc/sudoers
  3. insert username in file 'sudoers'
  4. save and exit ssh

Solution 9 - Linux

If you're unable to find visudo on your system

whereis visudo

Launch this tool

./PATH/visudo

add this line under

> User privilege specification

user_name ALL=(ALL)  ALL

Save the changes and here you go !

Solution 10 - Linux

First, switch/ log into the root user account or an account that has sudo privileges.

Next add the user to the group for sudo users:

  • If you're on Ubuntu members of the sudo group are granted with sudo privileges, so you can use this:

    sudo adduser username sudo
    
  • If you're on CentOS members of the wheel group are granted with sudo privileges, so you can use this::

    usermod -aG wheel username
    

Note: Replace username with your desired username.

To test the sudo access, log into the account that you just added to the sudo users grouP, and then run the command below using sudo:

sudo whoami

You will be prompted to enter the password. If the user have sudo access, the output will be:

root

If you get an error saying user is not in the sudoers file, it means that the user doesn’t have sudo privileges yet.

That's all.

I hope this helps

Solution 11 - Linux

Add your user to the list of sudoers. This will make it easier to execute commands as the user that you have created will require admin privileges.

sudo adduser username sudo

(Note:- Username is the user you want to give the privileges)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDanish ArmanView Question on Stackoverflow
Solution 1 - Linuxsanath metiView Answer on Stackoverflow
Solution 2 - LinuxRodney HowardView Answer on Stackoverflow
Solution 3 - LinuxSonal View Answer on Stackoverflow
Solution 4 - LinuxRobert SinclairView Answer on Stackoverflow
Solution 5 - LinuxwscourgeView Answer on Stackoverflow
Solution 6 - LinuxViktor KhilinView Answer on Stackoverflow
Solution 7 - LinuxBraian CoronelView Answer on Stackoverflow
Solution 8 - Linuxuser6670135View Answer on Stackoverflow
Solution 9 - LinuxOlivier D'AnconaView Answer on Stackoverflow
Solution 10 - LinuxPromise PrestonView Answer on Stackoverflow
Solution 11 - LinuxTejView Answer on Stackoverflow