1

I am trying to grant sudo privileges to a user of a CentOS 7 devbox by typing gpasswd -a user wheel, but the attempt is failing. What am I doing wrong?

Here is what I typed:

I discovered that the user is not in the wheel group as follows:

[user@localhost git]$ sudo yum install git
[sudo] password for user: 
Sorry, try again.
[sudo] password for user: 
Sorry, try again.
[sudo] password for user: 
user is not in the sudoers file.  This incident will be reported.

I then logged in as root and typed the following to add the user to the wheel group:

[user@localhost git]$ su -
Password: 
Last login: Thu Aug 20 17:11:31 PDT 2015 on pts/0
[root@localhost ~]# gpasswd -a user wheel
Adding user user to group wheel
[root@localhost ~]# exit
logout

I finally tried to use the sudo command again but it failed as follows:

[user@localhost git]$ sudo yum install git
[sudo] password for user: 
user is not in the sudoers file.  This incident will be reported.
[user@localhost git]$ 
  • 2
    What does groups show for the user? Group changes usually require logging out and back in to see them. – thrig Aug 21 '15 at 18:10
  • 1
    No, you just need a new session, which if under X11 might require logging out of X11 and back in. Or, SSH to localhost, that should create a new session (for that SSH session), among other such tricks. – thrig Aug 21 '15 at 18:15
3

Group changes on unix are not recognized by existing login sessions; assuming, say, a Linux system with the usermod command:

$ groups
user
$ sudo usermod -G wheel $USER
...
$ grep user /etc/group | grep wheel
wheel:x:10:user
$ groups
user

To see the group change, any existing sessions (e.g. SSH, X11, etc.) must be exited, and a new session made (e.g. open a new SSH connection, login in again via X11, etc):

$ ssh localhost
...
$ groups
user wheel

... or you could reboot the box, which would mandate new sessions be created once the host comes back up.

  • 1
    note that you could also just run "newgrp wheel" in an existing login session – Jeff Schaller Aug 21 '15 at 19:38
1

Your existing login session didn't load with the wheel group membership. Now that it's been granted, you can incorporate it by entering:

newgrp wheel

... without having to log out or reboot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.