在CentOS 7中将用户添加到wheel组时出错

Cod*_*Med 2 yum terminal sudo centos

我尝试通过键入 向 CentOS 7 devbox 用户授予 sudo 权限gpasswd -a user wheel,但尝试失败。我究竟做错了什么?

这是我输入的内容:

我发现该用户不在wheel组中,如下:

[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.
Run Code Online (Sandbox Code Playgroud)

然后,我以 root 身份登录并输入以下命令将用户添加到wheel组:

[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
Run Code Online (Sandbox Code Playgroud)

最后我再次尝试使用 sudo 命令,但失败了,如下:

[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]$ 
Run Code Online (Sandbox Code Playgroud)

thr*_*rig 5

现有登录会话无法识别 Unix 上的组更改;假设 Linux 系统具有以下usermod命令:

$ groups
user
$ sudo usermod -G wheel $USER
...
$ grep user /etc/group | grep wheel
wheel:x:10:user
$ groups
user
Run Code Online (Sandbox Code Playgroud)

要查看组更改,必须退出任何现有会话(例如 SSH、X11 等),并创建新会话(例如打开新的 SSH 连接、通过 X11 再次登录等):

$ ssh localhost
...
$ groups
user wheel
Run Code Online (Sandbox Code Playgroud)

...或者您可以重新启动盒子,这将要求在主机恢复后创建新会话。