How to Give a User Sudo Access on CentOS

There is two option to provide sudo access (administrator privileges) to existing or new users. The sudo command allows to run programs or commands with the security privileges of another user (by default, as the superuser).

Option 1 - Add User to the Wheel Group

The one way to grant sudo privileges is to add the existing user to the “wheel” group. "Wheel" group members are able to run all commands via sudo. Use the below usermod command to add the user to the "wheel" group.

usermod -aG wheel username

example: add username "yogi" to the wheel group
usermod -aG wheel yogi


Option 2 - Add User to "sudoers" File

The sudo privileges are configured in the /etc/sudoers file for users and groups. Adding the user to this file will grant customized access to the commands and configure custom security policies for the user. We can configure the user sudo access by modifying the sudoers file or by creating a new configuration file in the /etc/sudoers.d directory. The files inside this directory are included in the sudoers file.

sudo vim /etc/sudoers

Add the user under "Allows people in group wheel to run all commands".