Skip to Content

Enable root privilege for the group in the sudoers file

How to enable root privileges for the wheel/admin group from the sudoers file?

The 'wheel group' is a traditional term for a group of users who are granted superuser or administrative privileges. Members of the wheel group have the ability to perform critical system tasks and execute commands with elevated privileges using the 'sudo' command.

  • Make sure to take a backup of the sudoers file before making any changes.

root@server ~]# cp -p /etc/sudoers /etc/sudoers.backup

  • Make sure perl is installed on the server.

root@server ~]# apt install perl -y     #Ubuntu

root@server ~]# yum install perl -y     #CentOS

  • List all the groups on the server.

root@server ~]# cat /etc/group

  • If the user group is not available on the server, create the user group with the following command.

root@server ~]# groupadd admin          #Ubuntu

root@server ~]# groupadd wheel          #CentOS

How to grant root privileges to the wheel group on a CentOS server?

1. Login to the server and run the below command to add the user to the wheel group.

root@centos ~]# usermod -aG wheel username

2. Run the below command to find and uncomment the wheel privilege in the sudoers file.

root@centos ~]# perl -i -pe 's/^#\s*%wheel\s+ALL\s*=\s*\(\s*ALL\s*\)\s*ALL/%wheel ALL = ( ALL ) ALL/' /etc/sudoers

3. If the wheel privilege is not in the sudoers file, add it, and the user will gain administrative privileges.

root@centos ~]# cat /etc/sudoers | grep -i wheel

root@centos ~]# vim /etc/sudoers

%wheel ALL=(ALL) ALL

4. Login as the user on the server and run a command with 'sudo' to confirm that the user has administrative privileges.

user@centos ~]# sudo rm -rf /root/test_file.txt

How to grant root privileges to the admin group on a Ubuntu server?

1. Login to the server and run the below command to add the user to the wheel group.

root@ubuntu ~]# usermod -aG admin username

2. Run the below command to find and uncomment the admin privilege in the sudoers file.

root@ubuntu ~]# perl -i -pe 's/^#\s*%admin\s+ALL\s*=\s*\(\s*ALL\s*\)\s*ALL/%admin ALL = ( ALL ) ALL/' /etc/sudoers

3. If the admin privilege is not in the sudoers file, add it, and the user will gain administrative privileges.

root@ubuntu ~]# cat /etc/sudoers | grep -i wheel

root@ubuntu ~]# vim /etc/sudoers

%admin ALL=(ALL) ALL

4. Login as the user on the server and run a command with 'sudo' to confirm that the user has administrative privileges.

user@ubuntu ~]# sudo rm -rf /root/test_file.txt

 

Run the above commands in the parallel shell of Ezeelogin to uncomment the wheel group privileges across different server groups or all servers added to Ezeelogin.

Refer to the detailed article on parallel shell.