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?

2
  • 3
    Possible duplicate of Adding secondary groups and running processes
    – Jenny D
    Commented Jun 8, 2017 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
    Commented Apr 22, 2021 at 0:27

5 Answers 5

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.

1
  • Or you can start a new shell with newgrp wheel. Commented Jun 8, 2017 at 11:50
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?

1
  • %wheel ALL=(ALL) ALL is apparently uncommented by default
    – Why
    Commented Jun 8, 2017 at 11:51
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

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

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. Commented Apr 17, 2021 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .