How to add a CentOS user to the sudoers list

CentOS-LogoWhen you try to prefix a command with sudo on a fresh CentOS system you may be greeted with a message such as “you are not part of the sudoers list” and that the incident will be reported. Not the the FBI, but to a log file. And of course your sudo operation isn’t going to work.

That’s because individual users to the system need to be granted permission to executer root level commands, even if it’s only temporary. Here’s how to do it.

In essence, you need to add your user to a file called sudoers which lives in /etc/sudoers on CentOS 6.5. This file is read only, even to the root user – so before tweaking it we need to change its permissions, otherwise your edits can’t be saved:

chmod 666 /etc/sudoers

Now use your favourite text editor and find the following section:

vi /etc/sudoers

...

## Next comes the main part: which users can run what software on
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##     user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
youruser ALL=(ALL)  ALL

 

Add your own user name underneath the root user (as shown above), then save the file and exit. Don’t forget to change the file permissions back to 440 just like they were before:

chmod 440 /etc/sudoers

 

Jay is founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or drawing on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

You can leave a comment on my original post.