"'Username' is not in the sudoers file. This incident will be reported" [closed]
Asked Answered
A

11

168

After logging into ssh in a Linux machine, 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.

I need to have sudoers privilegies.

Amberly answered 14/12, 2017 at 5:43 Comment(3)
do your user have admin access? If no then login with root and add your user to /etc/sudoers fileEustashe
unix.stackexchange.com/questions/179954/…Monarch
And askubuntu.com/questions/2214/… And superuser.com/questions/866582/…Monarch
R
240

Open file

su root 
nano /etc/sudoers

Then add the user below admin user like below syntax.

user_name ALL=(ALL)  ALL
Robins answered 14/12, 2017 at 6:20 Comment(7)
Recommended way is to use visudo to avoid simultaneous edits (possibly not a problem in this case, but still...)Popeyed
It's only what the comment at the very top of the file makes clear "## This file MUST be edited with the 'visudo' command as root."Pyelonephritis
How does this make sense? The issue is that the user can't use sudo, so how can part of the solution be using sudo?Hitherto
Found that following in one of a video. It worked for me. Given that, we need to be in root mode. For that, ssh root@localhost, then sudo nano /etc/sudoersExpectorate
I dont like this answer. It should explain more than, this should be done through root user but he left that information making people confused.Ardent
@KansaiRobot You cannot su root if the user is not in the list of sudoers fileArdent
Even though sudo was not working for any other commands after an unattended install, su root did work, and after I was root I just ran usermod -a -G sudo myusername and it worked.Sherrell
T
87

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 
Tint answered 14/12, 2017 at 10:13 Comment(9)
Exaaaactly. Include OpenSuse under the 2nd group. In my case I I reversed the order, modifying sudoers before adding my user to wheel and ended up here.Andalusite
It's too much better this way, because you don't need edit none critical files for make this operation.Gorrono
Didn't worked on my Ubuntu 22.04 by on ContaboVolsci
@Mahesh User's process tree may need to be restarted.Candescent
It triggers the Permission denied issue.Gerri
usermod: command not found.Asylum
linuxize.com/post/how-to-add-user-to-group-in-linuxDonoghue
@Candescent yeah, it worked after I logged-out and then logged-in as the userVolsci
usermod: command not found. is there a package for this?Mombasa
G
44

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.

Giblets answered 20/7, 2019 at 12:12 Comment(0)
E
11

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

Exile answered 9/12, 2019 at 20:6 Comment(0)
B
8

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

Balbo answered 14/12, 2017 at 9:39 Comment(0)
H
7

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

Hickox answered 5/7, 2018 at 15:41 Comment(3)
I simply needed to log off and log back in after applying this solution.Molybdenum
What if my user already belongs to the wheel group but I still get "'Username' is not in the sudoers file. This incident will be reported."?Esra
@AdrianLopez the wheel syntax only makes sense if wheel is a sudoers group, which in your case it probably isn't. This answer is also not really helpful, but rather miss informing to be honest. By default wheel isn't in the sudoers file.Diphthong
I
7
  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

Interdependent answered 13/6, 2019 at 19:20 Comment(0)
P
6

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 !

Poppas answered 11/5, 2020 at 12:19 Comment(0)
S
4

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

Shayla answered 18/9, 2020 at 14:34 Comment(0)
D
4

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
Dravidian answered 30/12, 2020 at 3:35 Comment(0)
S
1

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 to.

Subtractive answered 15/4, 2020 at 4:35 Comment(1)
this won't work if the user can't use sudo which is what the original poster can't do hence the error message.Gorman

© 2022 - 2024 — McMap. All rights reserved.