error when adding user to wheel group in CentOS 7
Solution 1
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.
Solution 2
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.
Related videos on Youtube
RabT
Updated on September 18, 2022Comments
-
RabT over 1 year
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]$
-
thrig over 8 yearsWhat does
groups
show for the user? Group changes usually require logging out and back in to see them. -
thrig over 8 yearsNo, 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.
-
-
Jeff Schaller over 8 yearsnote that you could also just run "newgrp wheel" in an existing login session