CentOS 7でホイールグループにユーザーを追加中にエラーが発生しました。

CentOS 7でホイールグループにユーザーを追加中にエラーが発生しました。

入力を介してCentOS 7 devboxのユーザーにsudo権限を付与しようとしましたが、gpasswd -a user 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.

次に root としてログインし、次のコマンドを入力してユーザーをホイールグループに追加しました。

[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

最後に、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]$ 

ベストアンサー1

次のusermodコマンドを使用するLinuxシステムを想定すると、Unixのグループ変更は既存のログインセッションでは認識されません。

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

グループの変更を表示するには、既存のセッション(SSH、X11など)を終了して新しいセッションを作成する必要があります(新しいSSH接続を開く、X11を介して再度ログインするなど)。

$ ssh localhost
...
$ groups
user wheel

...または、ホストがバックアップされた後に新しいセッションを作成する必要があるボックスを再起動することもできます。

おすすめ記事