Wednesday, May 6, 2009

Grant sudo powers in RHEL/CentOS

Running as Root all the time is a dangerous tactic in a Unix based system, yet some commands can only be executed with superuser privileges. The sudo command allows a regular user to run selected commands with superuser privileges. This feature is included by default in Red Hat Enterprise Linux and CentOS systems, but it takes an extra step to get it working.

First you need to gain superuser privileges. Next, open the file located at /etc/sudoers. You need to locate the line that reads:
# %wheel ALL=(ALL) ALL
Now uncomment it by removing the hash mark (#) from the beginning of the line so it looks like this:
%wheel ALL=(ALL) ALL
Save a close the file. Now anyone who is a member of the wheel group will be able to use the sudo command. To add a user to this group, gain superuser priviliges and run this command:
/usr/sbin/usermod -aG wheel [username]
This will add the specified user to the wheel group, allowing that user to use the sudo command.

1 comment:

  1. On some systems, including versions of RHEL, the file /etc/sudoers needs to be mode 440 to work properly. You might want to mention this.

    ReplyDelete

Note: Only a member of this blog may post a comment.