Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I(root) excute "usermod -G sudo chauncey",it say that "sudo group doesn't exist"

Tags:

linux

OS: CentOS 7. When I (root) execute the command below, it says that "sudo" group cannot be found.

[root@localhost etc]# usermod -G sudo chauncey
usermod:“sudo” group doesn't exits

I also check file in /etc/group, and "sudo" doesn't exists in it. So, how can I create a "sudo" group correctly?

like image 391
Chauncey.Zhong Avatar asked Nov 30 '16 15:11

Chauncey.Zhong


2 Answers

Sudo is not directly a group. The groups/users having sudoer rights are defined in a configuration file that you can access using sudo visudo. Check out this file to find out how it is configured on your system. Here is a good introduction https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html.

In your case, you have different ways to give sudo rights to chauncey.

  1. find the group(s) having sudo rights in the sudoers file and add chauncey to one of these groups. For example, say you have this line in sudoers:

    # Members of the admin group may gain root privileges
    %admin ALL=(ALL) ALL 
    

    then, add chauncey to admin with sudo usermod -a -G admin chauncey.

  2. create a new sudo group (sudo groupadd sudo) and add this lines (sudo visudo). Then once again add chauncey to the group

    # the 'sudo' group has all the sudo privileges
    %sudo    ALL=(ALL:ALL) ALL 
    
  3. set a special rule for this user in the sudoers file using the following (note that there is no %, which is used to denote a group):

    chauncey    ALL=(ALL:ALL) ALL 
    

Note that for all the rules I mentioned, I used the default ALL everywhere. The first one is the user(s) allowed, the second one is the host, the third one is the user as you are running the command and the last one is the commands allowed. You can tune your rules if ALL is too broad for your usecase.

like image 186
Derlin Avatar answered Nov 14 '22 10:11

Derlin


In centos, you adduser to wheel group instead of sudo.

usermod - aG wheel username

like image 40
panoet Avatar answered Nov 14 '22 10:11

panoet