5
[user@localhost ~]$ su -
Password: 
Last login: ...
[root@localhost ~]# usermod -aG wheel user
[root@localhost ~]# exit
logout
[user@localhost ~]$ sudo echo 123
[sudo] password for user: 
user is not in the sudoers file.  This incident will be reported.

What do I do wrong?

Why
  • 61
  • 1
  • 1
  • 3
  • 3
    Possible duplicate of [Adding secondary groups and running processes](https://serverfault.com/questions/565613/adding-secondary-groups-and-running-processes) – Jenny D Jun 08 '17 at 11:59
  • Linux (and most posix systems) only load your group memberships during login. You'll have to log out and log back in for the system to pick up the change and your user account to be able to run `sudo`. – Joe Block Apr 22 '21 at 00:27

5 Answers5

11

My experience is that 'user' needs to log out and in again. Try the 'id' command to see if the system thinks that 'user' is in the wheel group or not.

Ed Greenberg
  • 166
  • 1
  • 5
3

In stock CentOS 7, wheel is not enabled in the default /etc/sudoers file.

## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

## Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL

Did you uncomment those lines?

Sven
  • 97,248
  • 13
  • 177
  • 225
0

I will share what worked well for me.

I could add the wanted users directly to the sudoers file by editing suoders file using any of the commands: nano /etc/sudoers or visudo

Then scroll to the highlited section in the picture and add the wanted users either local or domain users will work: sudoers file

Dave M
  • 4,494
  • 21
  • 30
  • 30
Asamoto
  • 1
  • 1
0

I had the same issue and solved it by logging out of the system and then logged in back again, trying the Sudo command and yes, it works.

Check the screenshot attached

harbinger
  • 1
  • 1
  • 1
    Please don't post screenshots of text. Inlcude the text in your answer instead, so it's readable by screen readers and search engines. – Andrew Schulman Apr 17 '21 at 13:34
0

I tried logging out and logging in, did not work. When I ran id and group, the wheel group was not seen in the output, despite using the usermod command.

What finally worked for me was a reboot.

PraveenMathew
  • 57
  • 1
  • 2
  • 7