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?


Overview: This article explains how to enable root privileges for users by assigning them to the wheel group (on CentOS) or the admin group (on Ubuntu) using the sudoers file. It provides step-by-step guidance on adding users to the appropriate group and modifying the sudoers file to grant them sudo access.


Wheel group: Its 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?

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

root@centos ~]# usermod -aG wheel username

Step 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

Step 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

Step 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?

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

root@ubuntu ~]# usermod -aG admin username

Step 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

Step 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

Step 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.


Related Articles:

Configure Automatic su or sudo

Enabling Virtualshell did not allow automatic su or sudo

How to add sub ssh users on remote servers and restrict commands via sudoers file