Configuring Sudoers on CentOS
Adding a user to the sudoers file on Red Hat or CentOS is a fairly simple process. All we need to do is edit the /etc/sudoers file as root, and add a line.
First, open up a terminal and switch to the root user by typing the following:
su -
Enter the root user's password, and then load the /etc/sudoers file in vi using the visudo command:
visudo
Scroll down until you find the following section:
## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL
Push 'i' to enter insert mode, and uncomment the second line so it looks like this:
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
Uncommenting this line gives everyone in the group "wheel" the ability to run all commands. Exit insert mode by pressing escape, and then save the file and exit the editor by typing ':wq' without quotes.
Now we need to add our user to the "wheel" group:
usermod -G wheel username
Substitute your username where it says username, of coarse. Type "exit" to exit the root shell. You should now be able to execute all commands as root by prefixing them with sudo. You may notice that certain commands such as ifconfig don't work with sudo as expected, and this is because /sbin is not in the user's path. The solution to this problem is covered in this post.