Error Adding User to Wheel Group in CentOS 7 – Solutions

centossudoterminalyum

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]$ 

Best Answer

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.

Related Question